So I've been trying to debug my jQuery.post() call, and have been getting some weird responses. I'm stuck on what to do next, if anyone had any suggestions, I'd really appreciate it.
所以我一直在尝试调试我的jQuery.post()调用,并且得到了一些奇怪的响应。我坚持下一步该做什么,如果有人有任何建议,我真的很感激。
<script type="text/javascript">
var debugresp;
var debugpost;
$("#scan .scanSide button.startScan").click(function() {
// ...
console.log("Scanning...");
debugpost = $.post(
"scan/scan.php",
{
"side": side
},
function(response) {
console.log(response);
/*...*/
},
"xml"
);
console.log("Sent data...");
});
<script>
The two console.log()
calls outside the $.post
work fine, the page returns 200 OK
with valid data under the Network tab (Debug tools/Chrome), but the internal console.log(response)
never fires.
$ .post之外的两个console.log()调用工作正常,页面返回200 OK,网络选项卡下的有效数据(调试工具/ Chrome),但内部console.log(响应)永远不会触发。
If you noticed, I saved the return from $.post
.
如果你注意到,我保存了$ .post的回报。
// JavaScript console, while page hasn't returned yet
debugpost.state()
// > "pending"
// After the page returns, and console.log(response) hasn't been called
debugpost.state()
// > "rejected"
I've never tried to deal with problems in jQuery.post
, but I wouldn't expect "rejected" from the jqXHR
that is returned from $.post
.
我从来没有尝试过处理jQuery.post中的问题,但我不希望从$ .post返回的jqXHR中“拒绝”。
Might anyone have more debugging suggestions or suggestions on how to approach this?
可能有人有更多的调试建议或建议如何处理这个?
Resources:
jqXHR jQuery.post(...)
资源:jqXHR jQuery.post(...)
1 个解决方案
#1
4
Problem solved: I had invalid XML that I was trying to parse.
问题解决了:我尝试解析的XML无效。
For anyone else reading this, try jqXHR's fail(function(jqXHR, textStatus, errorThrown)
to debug.
对于阅读此内容的其他人,请尝试jqXHR的失败(函数(jqXHR,textStatus,errorThrown)进行调试。
#1
4
Problem solved: I had invalid XML that I was trying to parse.
问题解决了:我尝试解析的XML无效。
For anyone else reading this, try jqXHR's fail(function(jqXHR, textStatus, errorThrown)
to debug.
对于阅读此内容的其他人,请尝试jqXHR的失败(函数(jqXHR,textStatus,errorThrown)进行调试。