本文介绍了Ajax请求不会转到IE中的服务器端(perl-cgi),但可以在mozilla,chrome中使用,请在jquery中提供相同的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了这样的ajax代码,它不能在IE中工作,但可以在chrome,mozilla中工作
请在jquery中提供相同的代码
I wrote ajax code like this,it is not working in IE but working in chrome,mozilla
please provide same code in jquery
function AJAXRequest(url, callback) {
var req = init();
req.onreadystatechange = processRequest;
/*
function init() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
*/
function init() {
var xmlreq = false;
if (window.XMLHttpRequest) {
// Create XMLHttpRequest object in non-Microsoft browsers
xmlreq = new XMLHttpRequest();
} else if (window.ActiveXObject) {
// Create XMLHttpRequest via MS ActiveX
try {
// Try to create XMLHttpRequest in later versions
// of Internet Explorer
xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
try {
// Try version supported by older versions
// of Internet Explorer
xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
doError(e2);
}
}
}
return xmlreq;
}
function processRequest () {
if (req.readyState == 4) {
if (req.status == 200) {
if (callback) callback(req);
}
}
}
this.doGet = function() {
req.open("GET", url, true);
req.send(null);
}
this.doPost = function(body) {
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(body);
}
}
推荐答案
这篇关于Ajax请求不会转到IE中的服务器端(perl-cgi),但可以在mozilla,chrome中使用,请在jquery中提供相同的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!