下面的脚本在 Firefox 和 Chrome 上运行良好,但我似乎无法让它在 ie 上运行,尝试了所有甚至降低浏览器安全性的方法,看看是否阻止了它,但我仍然无法让它运行.
function postData() {
var http = new XMLHttpRequest();
var url = "/scripts/remove_fr.php";
var params = "";
http.open("GET", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() { //Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
}
}
http.send(params);
}
$("#qwerty").click(function () {
$('#qwerty').remove();
});
</script>
最佳答案
IE7以下,使用ActiveXObject
对象代替XMLHttpRequest
所以你的代码应该是这样的:
function postData() {
var http;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
http = new XMLHttpRequest();
}
else {
// code for IE6, IE5
http = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "/scripts/remove_fr.php";
var params = "";
http.open("GET", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() { //Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
}
}
http.send(params);
}
关于javascript - XMLHttpRequest() 不适用于 IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9657942/