weixin_33696822 2011-08-05 15:31 采纳率: 0%
浏览 92

如何调试JSONP AJAX事件

I'm trying to get a JSONP AJAX request to go through, but I'm having problems figuring out why it's not working. Right now I have this call

$.getJSON(server_path+"formproxy.php?"+$(form).serialize()+"&action="+form.action+"&callback=?", function(data, status, xhr) {
    alert(data);
});

but when I run the script nothing seems to happen. The best I can figure is that the jsonp request is running into an error, but because it's a jsonp request it's not actually reporting the error, which is greatly hindering my debugging.

I've played around with

$.ajaxSetup({
    "error":function() {
        alert("error");
    }
});

and

$(document).ajaxError(function(e, xhr, settings, exception) {
    alert('failed');
});

but I can't get either of them to trigger.

I've output the target url to the console, namely

server_path+"formproxy.php?"+$(form).serialize()+"&action="+form.action+"&callback=?"

I can visit the outputted url and see that it is working and outputs ?({"result":"success"}) which seems right to me.

Looking at the console in Chrome, it doesn't even show the XHR, but I'm at least sure the $.getJSON() code is being reached thanks to breakpoints.

I should finally note that I'm not even concerned with getting data back from the AJAX call. I just need to send form data cross domain and let the formproxy.php script process it.

Any thoughts on why this may not be working or techniques to help me see what's happening inside would be much appreciated.

  • 写回答

1条回答

  • weixin_33694172 2011-08-05 15:35
    关注

    Have you tried looking at the Network Panel in Chrome developer tools? It will show you all the http requests/responses that are being made on your page. That way you can tell for sure whether the the getJSON call is making a request to the server, and what the server response is (if any).

    You can also use the Net panel in Firebug for this.

    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R