简体   繁体   English

在进行ajax调用时遇到错误?

[英]Getting the Error on making ajax call?

I have made an Ajax call to one of my pages sitting in the server. 我已经对服务器中的其中一个页面进行了Ajax调用。 When I am making the Ajax call, I am not getting the data. 当我进行Ajax调用时,没有得到数据。 But instead I am getting status 200 OK with red font-color in the firebug. 但是相反,我在萤火虫中获得了状态为200 OK且字体颜色为红色的状态。 I am not able to figure out what the problem is. 我无法找出问题所在。

I am making an ajax call to these api pages: 我正在对这些api页面进行ajax调用:

  [{"ID":"001","name":"Naidu","school":"Hyd","hobby":"cricket"}]

My ajax call is like: 我的ajax调用就像:

  $.ajax({ url: 'http://something.com/api/name',
       data:{},
     type: 'post',
      dataType: "json",
    success: function(output) {
     //alert("SUCCESS");
      alert(output);
    }});

Make sure API returns a status message when call is made. 确保在调用时API返回状态消息。

Also retured output should be in json format. 调整后的输出也应为json格式。 If you want to see exact output even if that is not json , remove DataType:"json" part from script and you should be able to see exact response. 如果即使不是json也要查看准确的输出,请从脚本中删除DataType:“ json”部分,您应该能够看到准确的响应。

Chances are that API isnt returning a message in one of the two cases or returned output is not json datatype. 在两种情况之一中,API可能不返回消息,或者返回的输出不是json数据类型。

确保您没有在执行跨域Ajax。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM