嘿,我有以下ajax POST电话:
function callAjax(what2Do)
{
jQuery.ajax({
url: "count.php?do=" + what2Do,
type: "POST",
data: "",
cache: false,
success: function(response, textStatus, jqXHR){
alert('done!');
},
error: function(jqXHR, textStatus, errorThrown){
alert(
"The following error occured: "+
textStatus, errorThrown
);
}
});
}
我一直收到错误在iE9中运行该页面时出现以下错误:错误但在所有其他浏览器中都可以正常运行。
如果没有在IE中运行,我会缺少什么?返回是简单的文本。
答案 0 :(得分:1)
我遗憾地不得不在遗留IE行为中执行速成课程来处理几乎相同的条件。在我的情况下,它归结为IE的顽固insistence使用他们自己的专有XDomainRequest对象来处理CORS。一些好的链接:
对于拒绝遵守标准的浏览器制作例外情况是令人反感的,我在项目中使用类似以下的内容来说明必要的情况:
// This is necessary due to IE<10 having no support for CORS.
function fallbackXDR(callObj) {
if (window.XDomainRequest) {
var xdrObj = new XDomainRequest();
xdrObj.timeout = callObj.timeout;
xdrObj.onload = function() {
handleSuccess(xdrObj.responseText);
};
xdrObj.onerror = function() {
handleError(xdrObj);
};
xdrObj.ontimeout = function() {
callObj.xdrAttempts = callObj.xdrAttempts++ || 1;
if (callObj.xdrAttempts < callObj.maxAttempts) {
fallbackXDR(callObj);
}
};
xdrObj.onprogress = function() {
// Unfortunately this has to be included or it will not work in some cases.
};
// Use something other than $.param() to format the url if not using jQuery.
var callStr = callObj ? '?'+$.param(callObj.urlVars) : '';
xdrObj.open("get", callObj.url+callStr);
xdrObj.send();
} else {
handleError("No XDomainRequest available.", callObj);
}
}//fallbackXDR()
答案 1 :(得分:0)
试试这个:
function callAjax(what2Do)
{
jQuery.ajax({
url: "./count.php",
type: "GET",
data: { 'do': what2Do },
cache: false,
success: function(response, textStatus, jqXHR){
alert('done!');
},
error: function(jqXHR, textStatus, errorThrown){
alert(
"The following error occured: "+
textStatus, errorThrown
);
}
});
}