【问题标题】:My defered result is not being passed correctly我的延迟结果未正确传递
【发布时间】:2018-04-24 20:35:22
【问题描述】:

ajax 调用返回的数据似乎是空的。当我取消注释 success: function(result) 块时,结果正确输出到控制台,所以我知道数据存在。但是,当我调用 request().done 时,延迟值显示为空。

function request(cat)
{    
    return $.ajax
    ({
     url: 'query.php',
     type: 'POST',
     data: {Category: cat},
     dataType: 'json'//, 
     //success: function(result) 
     //{  
     //  if(result) 
     //  {        
     //  console.log(result[0]); Result outputs to the console correctly
     //  }
     //}  
}); // end ajax call   
}

request().done(function(data) { console.log(data[0]); });  //array appears to be empty

【问题讨论】:

    标签: jquery ajax deferred


    【解决方案1】:
    your code
    if(result) 
    {        
      console.log(result.[0]);
    }
    

    应该如下替换

    if(result) 
    {        
      console.log(result[0]);
    }
    

    【讨论】:

    • 对不起,这不是我的问题。那个时期是一个错字,不应该在那里。我的问题是延迟值显示为空,而注释块显示正确。这个问题确实说明了这一点。
    猜你喜欢
    • 2012-04-19
    • 1970-01-01
    • 1970-01-01
    • 2016-04-04
    • 2018-09-20
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 2018-07-08
    相关资源
    最近更新 更多