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.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable