weixin_33738555 2011-07-07 14:31 采纳率: 0%
浏览 29

jQuery AJAX分析器错误

I am working on a small jQuery script which pulls json from a site on my domain. Have been working on it forever, and cant seem to get it. When I run the code with json as the "dataType" I get a status error of 0. However, when I put in jsonp, I get a status of 200 (OK), and a parsererror. The thing is, when I copy the contents of the json to a text file, I can grab it and parse it perfectly with "json" as the datatype. So, not sure where to go from here. Any help would be appreciated.

<HTML>
<BODY>
<script type ="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script><script type="text/javascript">    
$(document).ready(function() {
$.ajax({
type: "GET",
contentType: "application/json",
dataType: "json",
url:"*blocked for security purposes*",
success: function(data){
    alert("Successful");
    console.log(data)
},
error: function(xhr, thrownError){
    console.log('ERROR: ' + thrownError);
    alert("status:" + xhr.status);
                alert("threw:" + thrownError);    }
}); });

</script>

</BODY>
</HTML>
  • 写回答

1条回答 默认 最新

  • weixin_33744854 2012-03-02 20:06
    关注

    Duplicate of various other qustions, see here for an answer:

    https://stackoverflow.com/a/4969486/289203

    Basically, JSON-P is NOT json, instead, it's javascript which calls a function passing that function JSON.

    E.g.

    JSON response:

    {"a":"cat"}

    JSON-P response:

    callmyjsonfunction({"a":"cat"})

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器