Javascript jquery ajax调用在IE9中不起作用
我对下面的代码有一些问题。它不会在IE9中运行。不过,它在其他浏览器中也可以正常工作。 我已经在代码中放置了一个警报,但未到达该代码段。 有人知道如何解决这个问题吗Javascript jquery ajax调用在IE9中不起作用,javascript,jquery,ajax,Javascript,Jquery,Ajax,我对下面的代码有一些问题。它不会在IE9中运行。不过,它在其他浏览器中也可以正常工作。 我已经在代码中放置了一个警报,但未到达该代码段。 有人知道如何解决这个问题吗 NWF$.ajax({ url: 'http://pdfservice/training/', data: JSON.stringify(dataJSON), contentType: 'application/json; charset=utf-8', dataType: 'json', type: 'POST',
NWF$.ajax({
url: 'http://pdfservice/training/',
data: JSON.stringify(dataJSON),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
type: 'POST',
cache: false,
success: function (fileName) {
alert('ok!');
window.location.href = 'http://pdfservice/training/?meeting=' + fileName;
},
error: function (result) {
alert(JSON.stringify(result));
}
});
我刚刚更改了失败到错误,这是我得到的错误:
{"readyState":0,"status":0,"statusText":"No Transport"}
这是因为JSON数据已损坏
修复JSON数据,您可以使用验证JSON响应以确保它是有效的JSON。Jquery w Ajax for IE9被破坏 这是通过一个
“在jQuery 1.5+中使用$.ajax函数时,使用IE8和IE9的XDomainRequest对象实现自动跨源资源共享支持。”Old post,我想我会从 如果代码被删除,我将添加代码:
if (!jQuery.support.cors && window.XDomainRequest) {
var httpRegEx = /^https?:\/\//i;
var getOrPostRegEx = /^get|post$/i;
var sameSchemeRegEx = new RegExp('^'+location.protocol, 'i');
var xmlRegEx = /\/xml/i;
// ajaxTransport exists in jQuery 1.5+
jQuery.ajaxTransport('text html xml json', function(options, userOptions, jqXHR){
// XDomainRequests must be: asynchronous, GET or POST methods, HTTP or HTTPS protocol, and same scheme as calling page
if (options.crossDomain && options.async && getOrPostRegEx.test(options.type) && httpRegEx.test(userOptions.url) && sameSchemeRegEx.test(userOptions.url)) {
var xdr = null;
var userType = (userOptions.dataType||'').toLowerCase();
return {
send: function(headers, complete){
xdr = new XDomainRequest();
if (/^\d+$/.test(userOptions.timeout)) {
xdr.timeout = userOptions.timeout;
}
xdr.ontimeout = function(){
complete(500, 'timeout');
};
xdr.onload = function(){
var allResponseHeaders = 'Content-Length: ' + xdr.responseText.length + '\r\nContent-Type: ' + xdr.contentType;
var status = {
code: 200,
message: 'success'
};
var responses = {
text: xdr.responseText
};
try {
if (userType === 'json') {
try {
responses.json = JSON.parse(xdr.responseText);
} catch(e) {
status.code = 500;
status.message = 'parseerror';
//throw 'Invalid JSON: ' + xdr.responseText;
}
} else if ((userType === 'xml') || ((userType !== 'text') && xmlRegEx.test(xdr.contentType))) {
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.async = false;
try {
doc.loadXML(xdr.responseText);
} catch(e) {
doc = undefined;
}
if (!doc || !doc.documentElement || doc.getElementsByTagName('parsererror').length) {
status.code = 500;
status.message = 'parseerror';
throw 'Invalid XML: ' + xdr.responseText;
}
responses.xml = doc;
}
} catch(parseMessage) {
throw parseMessage;
} finally {
complete(status.code, status.message, responses, allResponseHeaders);
}
};
xdr.onerror = function(){
complete(500, 'error', {
text: xdr.responseText
});
};
xdr.open(options.type, options.url);
//xdr.send(userOptions.data);
xdr.send();
},
abort: function(){
if (xdr) {
xdr.abort();
}
}
};
}
});
};
jQuery.support.cors = true;
您的控制台中是否出现异常?哪个版本的jquery?它是任天堂使用的jquery,我认为它使用的是1.10.1版本的jquery。不,在删除
dataType
后,我在控制台中没有看到任何异常。我在我的页面中包括了jquery.xdomainrequest.min.js,但它仍然不起作用。