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
Post a Comment