I’m building a PhoneGap Mobile application where I get data from a server with getJSON every three minutes. Because it will be a mobile app, the connection won’t be guaranteed all the time so I would like to inform the user when was the last time that the getJSON function was successful, how can I achieve this?
I’m building a PhoneGap Mobile application where I get data from a server with
Share
One approach would be to print to the screen every time the method is successful in the success callback of
getJSON, something like this perhaps:Another approach would be to save the current time in the success block and then if there is an error in the
getJSONcall, alert the user that the last timegetJSONsucceeded was at that previously stored value. Something like this:This should give you the general idea of two ways to solve this problem.
UPDATE
Searching around I found this article about defensive AJAX calls that you could try as well.