2013-09-24 33 views
-1

当一个帖子失败时,你会调用哪个jQuery AJAX事件?例如,如果该网站会记录此消息:当POST失败时,你会调用什么样的AJAX事件?

POST http://s-t-h-c.appspot.com/dispatch 500 (Internal Server Error)

其AJAX事件处理程序处理呢?例如,如果请求是成功的,我们可以使用:

$.ajax({ 

success: function() { 
} 

}); 

我已经尝试过error:ajaxError:,但他们似乎并没有能够赶上这个问题。

任何帮助将不胜感激!谢谢!

〜Carpetfizz

+2

为什么不阅读'$ .ajax()'文档? – undefined

+0

我已经做了,由于某些原因'错误'没有奏效。 – Carpetfizz

回答

1

为您添加success:同样有error:在阿贾克斯

为样本代码,我会在这里发布一个

$.ajax({ 
    type: 'GET', 
    dataType: 'json', 
    url: url, 
    timeout: 5000, 
    success: function(data, textStatus){ 
     alert('request successful'); 
    }, 
    error: function(xhr, textStatus, errorThrown){ 
     alert('request failed'); 
    } 
    }); 

干杯!

+0

非常感谢,这工作!我意识到我正在使用'error :()'的错误参数 – Carpetfizz

0
$.ajax(

     { 

     type: "GET", 

     cache: false, 

     url: url, 

     dataType: "xml", 

     contentType: "text/html", 

     success: processData, 

     error: errorAlert 

     }); //end of AJax 



//Package the code that handles 

     //error message in case the request 

     //is not successful: 

     function errorAlert(e, jqxhr) 

     { 

     alert("Your request was not successful: " + jqxhr); 

     } 
相关问题