egoselfaxis
asked on
Need help troubleshooting javascript for keeping PHP session alive using ajax
I have the following javascript that doesn't appear to be doing anything. It;s supposed to make an ajax request and display an alert messagee very 5 seconds, .. but it doesn't appear to be working at all:
The answer is probably simple, .. but I'm drawing a blank. Can anyone here maybe spot what might be wrong with the script? It's not even throwing any errors. I just never see the expected alert message.
Thanks,
- Yvan
<script type="text/javascript">
var refreshSn = function () {
var time = 5000; // 5 secs
settimeout(
function ()
{
$.ajax({
url: '../user/refresh_session.php',
cache: false,
complete: function () {refreshSn();}
});
alert('Session Re-started!');
},
time
);
};
</script>
The answer is probably simple, .. but I'm drawing a blank. Can anyone here maybe spot what might be wrong with the script? It's not even throwing any errors. I just never see the expected alert message.
Thanks,
- Yvan
Are you loading jQuery before that? You are using jQuery syntax.
ASKER
Gary .. I'm not sure I understand your comment.
Are you saying that it's impossible for this script to work?
And yes Dave .. I am loading jquery before that.
- Yvan
Are you saying that it's impossible for this script to work?
And yes Dave .. I am loading jquery before that.
- Yvan
ahh ignore me I missed you were calling the function again.
URL should be a proper url, this will not work as their is no relative path as far as jquery is concerned.
url: '../user/refresh_session.p hp',
It should be the full url (domain) or the path in relation to the root.
url: '../user/refresh_session.p
It should be the full url (domain) or the path in relation to the root.
ASKER
No, you're mistaken. All of my other ajax functions within the same page are using relative paths and are all functioning just fine.
- Yvan
- Yvan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@egoselfaxis - nowhere in your code are you actually calling your function. You define it, but never call it!! Call it when the document is ready:
$(document).ready(function() {
refreshSn();
});
Also, javascript is case sensitive - settimeout() is wrong. It should be setTimeout()
ASKER
Thank you! It works now!
setTimeOut is a one off command.