我使用$.post在我的网页中发送和接收响应。但它在Internet Explorer中不起作用。我使用了Ajax的另一种方式。我必须创建xmlhttprequest对象。
我的代码是
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","demo_post2.asp",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("fname=Henry&lname=Ford");这对于除ie-10之外的所有浏览器都能正常工作。我写了如下代码来支持ie-10。
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP.6.0");
}它不适用于mozila,safari,但适用于ie-10。我还没有和ie-7核对过。这是一个冲突。请向我提供任何帮助.
发布于 2013-08-10 13:56:07
尝试使用第一种方法,并将send函数封装为如下的shownn
setTimeout(function () {
xmlhttp.send();
}, 0);https://stackoverflow.com/questions/18158804
复制相似问题