开发者

Display jQuery $.ajax 503 error response

I'm trying to display the response of a file that responds with an 503 error.

function netbootupdate() {


$("#netbootstatus").html('Updating..'); 
  $.ajax({
    type: 'GET',
    url: 'clientarea.php',
    dat开发者_StackOverflow中文版a: 'action=productdetails&id=' + $('#serverid').val() + '&modop=custom&a=netbootset&netbootid=' + $('#netbootid').val() + '&root=' + $('#root').val(),
    timeout: 5000,
    success: function(data) {
      $("#netbootstatus").html(data);
      $("#status").html(''); 
    },
    error: function(data) {
      $("#status").html(data);
      $('#status').addClass('errorbox');
    }
    });
}

For some reason data doesn't give me the content of the reply.


$.ajax({
   // ...
   // [other arguments]
   // ...
   error: function(xmlReq, txtStatus, errThrown){
     $('#status').text(xmlReq.responseText).addClass('errorBox');
   }
});

I think that's what you're going for, though not sure. Either way, the xmlReq (as I've named it) has several properties associated with it you can access and reference.


AFAIK, In some browser, XHR refuse to pass data over when the status is anything but 2xx, 3xx. If you do need the data of a 503 response, try to rewrite the HTTP status code on server side.

In complete(data, textStatus, XMLHttpRequest) callback, you may check textStatus for string error to detect 503. (Oh I just realized you already know that)

ref: http://api.jquery.com/jQuery.ajax/

Edit: Use complete() instead of success() to catch all of the results.


I don't know if this helps, but I have a web service that I force to throw a 503 Error when the database is unavailable. It correctly returns a HTTP 503 response code, but in my client-side script the AJAX Response code returned is 500 (server error). You might like to have a generic 5** response code handler, rather than a specific 503, so you can catch all server-related issues. This is what I ended up doing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜