javascript - Alert message if there is new data on server -


i'm building simple phonegap application new messages mysql server , show them user. application supposed json

 {     "key": [         {             "message": "test"         }     ] } 

from server every minute , alerts if there new. right alerts message "test" every time though json has changed this:

{"key":[]} 

after application has asked server first time.

this js use

 setinterval ( "getmessages()", 60000 ); function getmessages() {     $.getjson(serviceurl + 'messages.php' ,function(result){     $.each(result.key, function(index, field){     alert(field.message);   }); }); } 

the request being cached browser. change url to:

serviceurl + 'messages.php?' + new date().gettime() 

this trick browser thinking it's different request each time , therefore avoids issues caching.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -