0

I have an strange behavior of this synchronous ajax call when having a weak wlan internet connection on my tablet.

If connection is fine, I'll get "ok", if the connection is lost, I'll get "fail", but if the connection is lost during the request I'll get nothing at all.

My guess is, that the request was sent within the timeout, but while retrieving the data from the ajax call the internet connection broke down and so neither done nor fail will be fired. Do you have any ideas what kind of problem may occur? The best solution should be, that it fires "fail" when connection gets los during the request.

$.ajax({
    url: "/callme.php',
    type: "GET",
    async: false,
    timeout: 3000
})
.done(function(data) {
    alert("ok");
})
.fail(function(data) {
    alert("fail");
});

EDIT: Not, this is not a duplicate question... the timeout doesn't work as expected when you have a weak connection with temporary internet loses.

Marco
  • 3,470
  • 4
  • 23
  • 35
  • The problem is moot anyway, as you shouldn't be using synchronous request. Remove `async: false`. – Rory McCrossan Jan 18 '18 at 12:03
  • Possible duplicate of [Set timeout for ajax (jQuery)](https://stackoverflow.com/questions/5225597/set-timeout-for-ajax-jquery) – Esteban Garcia Jan 18 '18 at 12:03
  • Not, this is not a duplicate question... the timeout doesn't work as expected when you have a weak connection with temporary internet loses. – Marco Jan 18 '18 at 13:20
  • @RoryMcCrossan: I need an synchronous request in this case... – Marco Jan 18 '18 at 13:22
  • Are you making the request in the `onbeforeunload` event? That's the only time a synchronous request is applicable. Otherwise you should be using the async callback pattern. – Rory McCrossan Jan 18 '18 at 13:23
  • @RoryMcCrossan: In the software the ajax request is send to book a transaction. I have to do this in a synchronous request beacuse I have to wait for the response (ok/not ok) to decide afterwards how to continue in the software. – Marco Jan 18 '18 at 13:37
  • 1
    That is exactly why you *should be using an async* request. Use the callback pattern properly and you will have no issues. – Rory McCrossan Jan 18 '18 at 13:38
  • @RoryMcCrossan: I'll do it with async callbacks... it is possible to refactor the software. – Marco Jan 25 '18 at 21:29

0 Answers0