【问题标题】:Opposite of success: function(data) - ajax成功的反面:函数(数据) - ajax
【发布时间】:2016-01-20 09:18:28
【问题描述】:

什么是->成功的反义词:函数(数据)

 $.ajax({
   type: "POST",
   cache: false,
   url: "/p.php",
   data: info,

   success: function(data){

我想检查它是否不成功,而不是它是否成功......

【问题讨论】:

  • 试试error: function(){}
  • @ShaminderSAujla 我不能同时使用两者,成功:函数(数据){} 错误:函数(数据){}?
  • 当然,你可以同时使用它们,还有beforeSendcomplete等。您可以在单个 ajax 中使用它们。

标签: ajax


【解决方案1】:

你用成功函数捕捉成功情况,还有错误函数。请参阅文档http://api.jquery.com/jquery.ajax/

有关详细的 xhr 捕获机制,请参阅this

$.ajax({
    type: "POST",
    cache: false,
    url: "/p.php",
    data: info,
    success: function(data){
        //do something
    },
    error: function(jqXHR, textStatus, errorThrown){
        console.log(errorThrown);
    }

【讨论】:

  • 对您的答案进行一些解释会很棒
  • 如果 /p.php 没有找到,它没有显示任何错误,为什么?
  • 你试过statusCode 吗?作为statusCode: { 404: function() { alert( "page not found" ); },500: function() { alert( "internal error" ); } }
猜你喜欢
  • 2014-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-18
  • 2013-03-25
  • 2015-06-29
  • 1970-01-01
相关资源
最近更新 更多