JQuery $.ajax calls success method on timeout, instead of error, running in Safari or Chrome

JQuery $.ajax calls success method on timeout, instead of error, running in Safari or Chrome



Hello, I've noticed this weird behaviour of jQuery in Safari and Chrome (didn't test on Firefox as I'm using some webkit CSS extensions). After setting up the call like this:


  1. $.ajax( {
  2. 'url' : url,
  3. 'dataType' : 'json',
  4. data : reqdata,
  5. cache: false,
  6. method: 'get',
  7. timeout: 20000, //10 secs of timeout 
  8. success : function(data, textStatus, XMLHttpRequest) {
  9. console.log("success");
  10. if ((data === null) || (data.length == 0)) {
  11. ts.doAction( {
  12. 'actionName' : 'timeout',
  13. 'request' : {
  14. 'reqdata' : reqdata,
  15. 'actionName' : actionName,
  16. 'url' : url
  17. },
  18. 'controller' : ts
  19. });
  20. }

  21. ts.doAction( {
  22. 'actionName' : actionName,
  23. 'data' : data
  24. });
  25. },
  26. error : function(XMLHttpRequest, textStatus, errorThrown) {
  27. console.log("error: " + textStatus);

  28. if (textStatus == "timeout") {
  29. ts.doAction( {
  30. 'actionName' : 'networkFailureError',
  31. 'request' : {
  32. 'reqdata' : reqdata,
  33. 'actionName' : actionName,
  34. 'url' : url
  35. },
  36. 'controller' : ts
  37. });
  38. } else {
  39. ts.doAction( {
  40. 'actionName' : 'serverError',
  41. 'request' : {
  42. 'reqdata' : reqdata,
  43. 'actionName' : actionName,
  44. 'url' : url
  45. },
  46. 'controller' : ts
  47. });
  48. }
  49. }
  50. });

If a timeout occurs (I switch the local webserver off), the 'success' method will be called! More than this in the textStatus parameter there is a string with "success" !!! The error handler doesn't even get called.... (As you may notice the only way I had to tell the problem, was to check the data param if it is null or 0 length... Why this behaviour? How can I avoid this?