【发布时间】:2014-06-02 11:10:17
【问题描述】:
我已经解决这个问题几天了,并在这个论坛上联系,因为我觉得我已经用尽了我的选择。我有一个托管在 Drupal 7 网站上的表单,需要将表单值提交到外部 url。该表单通过 jQuery.AJAX 使用 HTTPS 协议上的 POST 请求
- Form 在 Chrome、Firefox 和 Safari 中运行良好
- 我在 IE10+ 控制台中收到以下错误(使用 IE10+ 时,ajax 调用总是进入错误函数):
SCRIPT7002:XMLHttpRequest:网络错误 0x2ef3,由于错误 00002ef3 无法完成操作
我尝试了以下方法:
-
添加内容类型:
// causes all of the jQuery callbacks to error out "application/json; charset=utf-8", 在实际 POST 之前尝试 Ajax GET 调用(如另一个 SO 线程上的建议)
在请求中添加了
header( 'Content-Type: application/json; charset=utf-8' );设置
crossDomain: true
已添加相应的 CORS 标头,并将表单代码粘贴在下方:
$.ajax({
url: "[URL]", //the page to receive the form data
crossDomain: true,
type: "POST",
data: dataString, //posting to API
dataType: "json", //the data type the function should expect back from the server
success: function(data) {
if (data.response_status == "1") { //error for at least 1 field
//display error message
}
else {
//display thank you label next to input
}
} else {
//All form fields completed successfully! Redirect user to Thank you confirmation page
}
},
error: function(jqXHR, textStatus, errorThrown) {
alert("there is an error!");
console.log("in error section");
console.log("jqXHR: " + jqXHR);
console.log("jqXHR.responseText: " + jqXHR.responseText);
console.log("textStatus: " + textStatus);
console.log("errorThrown: " + errorThrown);
data = $.parseJSON(jqXHR.responseText);
console.log("parseJSON data: " + data);
}
});
});
});
任何指导都会有所帮助!谢谢
【问题讨论】:
-
感谢您的建议!我一直在使用 Live HTTP Headers 和 Firebug,但 Fiddler2 肯定更详细。真正有趣的是,如果我允许 Fiddler 解密 HTTPS 流量,一切正常!我得到了完整的请求和响应,包括预期的 CORS 标头和 JSON 数据。一旦我取消选中解密 HTTPS 或停止捕获流量 (F12) 的选项,我就会再次获得中止的连接。任何想法为什么使用 Fiddler 有效? HTML表单端的SSL证书是否有问题(它没有过期或任何东西)?
-
啊,我刚找到你的博文!需要通读所有不同的场景。感谢您为我指明正确的方向! blogs.telerik.com/fiddler/posts/13-02-28/…
-
@EricLaw,我检查了 SSLLabs.com 并且证书在表单/应用服务器上都没有任何错误。还使用了 TLSv1.0(通过 Fiddler 和 SSLLabs 确认)、HTTP 1.1、Connection: Keep-Alive。所以我不确定为什么当我使用 Fiddler 时连接也没有中止......你遇到过类似的事情吗?再次感谢你
标签: javascript php jquery json internet-explorer