Eran Shmuel
Eran Shmuel

Reputation: 149

updating database with ajax- handling with errors

Im building a website where the user uses ajax calls in order to update the database. Its works well on xammp but im worried that problems may happen frequently when the site will be on the net. i've got some questions:

  1. If ajax fails (and my code is good), is it always because of connections?
  2. Can an attempt fail but succeed later?
  3. What is the best way to handle those failed requests?

Upvotes: 0

Views: 139

Answers (1)

Dragony
Dragony

Reputation: 1722

If ajax fails (and my code is good), is it always because of connections?

An Ajax call can fail for a variety of reasons. Reasons can be, but are not limited to: Javascript error, Network Timeout, Serverside error, JS Performance, Browser settings, etc

Can an attempt fail but succeed later?

If your AJAX request fails it will not automaticly retry. You need to program that yourself.

What is the best way to handle those failed requests?

You should have error handling in javascript to check for the errors. Basicly there are 3 cases:

  • Correct response from server
  • Response from server, but with incorrect return (failed serverside)
  • No Response from server (failed clientside)

You can either notify the user of a failed request or retry a few times and notify the user later, if the request never completes.

Upvotes: 1

Related Questions