0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, no response is recognized with: error: function(jqXHR, textStatus, errorThrown) {} right? how can i know if connection is lost? and can i lose connection and regain it?
The easiest way to detect an error is to have your server return a predefined response (for example 'done'). If you don't recieve the response, then something went wrong and you can retry (for example after 10 seconds).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.