[英]inner html doesn't work in ie but works in ff
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
var Buffer= xmlHttp.responseText;
Buffer= Buffer.split("#%~");
document.getElementById("Template").innerHTML = Buffer[0];
document.getElementById("Template1").innerHTML = Buffer[1];
alert(Buffer+"Buffer");
The above code doenot work in ie but it works fine in ff. 上面的代码在ie中不起作用,但在ff中可以正常工作。 i tried even with other options but coulnt get it.
我什至尝试了其他选择,但很想得到它。 alert shows same values in ie & ff but its of no use as it doesnt print in ie.
警报在ie&ff中显示相同的值,但是它没有用,因为它不会在ie中打印。 can anyone help?
有人可以帮忙吗?
internet explorer dont have the standart XMLHttpRequest
object so you have to use the ActiveXObject
Internet Explorer没有标准的
XMLHttpRequest
对象,因此您必须使用ActiveXObject
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 8 and older
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
that makes sure httpRequest is working in IE aswell. 确保httpRequest在IE中也能正常工作。 on a side note, you probly wanner look in to using
console.log
insted of alert
then you get a nice output in youre developer tools (F12 on windows) 在旁注中,您可能希望使用
console.log
插入alert
然后在开发人员工具中获得不错的输出(Windows上为F12)
You don't state this, but you need to be creating your xmlHttp
object differently for certain browsers — especially Internet Explorer: 您无需说明,但是需要为某些浏览器(尤其是Internet Explorer)以不同的方式创建
xmlHttp
对象:
var xhttp = function(){
var obj = null, er = null;
if(typeof XMLHttpRequest != 'undefined'){
obj = new XMLHttpRequest();
}
else {
try{
obj = new ActiveXObject('Msxml2.XMLHTTP');
}catch(er){
try{
obj = new ActiveXObject('Microsoft.XMLHTTP');
}catch(er){
obj = null;
}
}
}
return obj;
}
The usage of the following code would be: 以下代码的用法是:
xmlHttp = xhttp();
From then on you can use xmlHttp
in roughly the same manner as you are doing, there are certain pitfalls / differences to be aware of, this is the reason why it is good to use a library as stated by Adrian.. however it is even better to understand the underlying differences first. 从那时起,您可以使用与您大致相同的方式来使用
xmlHttp
,要注意某些陷阱/差异,这就是使用Adrian所说的库的好原因。最好先了解潜在差异。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.