views:

376

answers:

2

I would like some recommendations on the best way to handle errors in AJAX-powered applications. Specifically, the methods used to log the errors and what do you do to address them.

An obvious priority is that I don't want any user input lost. I was hoping to come up with some sort of fallback mechanism so that if an AJAX post fails, a natural form POST can be attempted using the same data. Any suggestions?

A: 

So your question is really "How do I make sure there aren't any client-side errors?"

You need to test it extensively.

A post is a post no matter what, if one fails the other one is likely to also.

If you want an idea, you could start keeping a client side javascript log and if an error occurs you could post to a general error handling page that stores the log for safe keeping.

But then what if that errors? You could go on and on, but really: just test it thoroughly and you'll end up with minimal client side errors.

Nathan
+1  A: 

Use the command pattern: User actions could be considered commands, such as "user entered this text" or "user moved this thing here." Each command could be an object stored in a FIFO queue. As the more commands are executed, subsequent Ajax calls post them to the server. If an Ajax post fails, the commands simply build up in the queue until the client is able to post them.

a paid nerd