views:

54

answers:

1

Currently I am pulling a JSON feeds from numerous APIs using jQuery, but what is the best way to handle the possibility of a service not responding or timing out because of their server? Would it be better to cache the JSON on your server? I'm using PHP/MySQL so I'd like to see an example if a server-side solution is the way to go.

A: 

The best way to handle it would be to display a message to the user that says something like "Sorry, the server could not be contacted. This probably isn't your fault." Is that what you meant? If not, try giving more detail in your question.

You should definitely cache the JSON on the server, if it makes sense to do so. You should cache everything when it makes sense to do so.

Garrett Albright
I would rather not give a message just saying "Sorry," I would like to always be able to show results somehow. What is the best way to do that? (I am using PHP/MySQL)
Keith
Maybe I'm still not understanding your question, but if you're not successfully fetching results from the server, how do you expect to be able to show them? And we're talking JavaScript/jQuery here, so what you're running on the server is irrelevant.
Garrett Albright
…Or are you saying you're fetching feeds from external servers to your servers using PHP? If so, then what does jQuery have to do with it?
Garrett Albright
Right now I am fetching feeds from various web services using jQuery, but I realized that there's a possibility that those services might be slow to respond or not respond at all. My question is about handling that scenario (e.g. caching the feeds on your server or storing in your database) so you're not relying on external sites.
Keith
If I'm going to use jQuery, I would like to display "retrying in (number of seconds)" countdown if the feed doesn't respond, and have a button to allow the user to try to load the feed again. Any suggestions on how I could do that?
Keith