last day (14 days later) » 

9:28 AM
0
A: Polling mechanism through an Ajax call

user3906922setTimeout will fire a timer only once. Use setInterval to execute code every X seconds: function pollServerForNewMail() { setInterval(function(){ // Code in this function will run every 10 seconds $.ajax({ url: "server", success: function(data){ alert("TEST"); ...

 
you could easily change it back to setTimeout and call the function again once ajax return, but thats not how i understood the author..
 
I used setTimeout. But it did not appear the alert at least once. Actually I need to firstly appear the alert at the page load. After every 10 seconds it should dispalyed. Do you have any idea why it did not call at the page load. I just put the function name inside script tags to call the function at page load.
 
add the entire html page to your question
 
I added my two pages to the question.
 
in polling.jsp there is a missing } at the end of pollServerForNewMail function
 
9:28 AM
sorry. when I copying the code here, there was a mistake. But I have put it in the code. Let me just edit the post. But still it does not work :(
 
9:41 AM
if you add alert(); after the call to pollServerForNewMail() , do you see it?
 
sorry. I did nt get you
ah oki Ill check it
yes then it is showing.
It means the function is calling
 
10:03 AM
so the alert('TEST') is showing?
 
no that's not like that
what I did was put an alert function pollServerForNewMail() {
alert("Test")
function pollServerForNewMail() {
alert("Test") <rest of code>}
and then it dispalyed the alert Test
you wanted me to do that?
 

last day (14 days later) »