IE 的 AJAX document.getElementById().innerHTML 问题?
在有人说我没有阅读之前,我可能会说我几乎阅读了与我的问题相关的所有内容。但我找不到答案。 因此,我有一个简单的 AJAX 脚本,可以将外部文件加载到预定义的 div 中。这是这些脚本的代码:
function loadTwitter()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your Browser Don't Support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById("column_twitter").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("GET","../includes/home/twitter.php",true);
xmlHttp.send(null);
}
它在我测试的每个浏览器(FF、Opera、Chrome、Safari)中工作得很好,但在 IE7 中不想将我的外部 php 文件注入到预定义的 div 中。它始终保留我在 div 内编写的默认文本... 我认为问题出在这一行:
document.getElementById("column_twitter").innerHTML=xmlHttp.responseText;
那么,有什么建议如何解决 IE(7 及以上版本)的问题吗?
Before someone said that I did not read I may say that I read almost everything linked with my question. But I couldn't find my answer.
So, I have a simple AJAX script that loads my external file inside predefined div. This is the code of those script:
function loadTwitter()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your Browser Don't Support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById("column_twitter").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("GET","../includes/home/twitter.php",true);
xmlHttp.send(null);
}
It works just fine in everyone browser that I test (FF, Opera, Chrome, Safari), but inside IE7 don't want to inject my external php file into predefined div. It always stays the default text that I wright inside div...
And I think that the problem is in this row:
document.getElementById("column_twitter").innerHTML=xmlHttp.responseText;
So, any suggestions how to fix this for IE (7 and above)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你最好使用 JavaScript 框架,例如 jQuery ,它可以让你专注于实现你的功能而不是浏览器兼容性和低级网络交互。使用 jQuery 你可以简单地执行以下操作:
I think you'd be better off using a javascript framework such as jQuery that allows you to concentrate on getting your features implemented rather than browser compatibility and low level network interaction. Using jQuery you could simply do:
我知道这是一个老问题,但我今天遇到了类似的问题,我想将其发布给其他人,以防您遇到此问题。这可能是由于您的“column_twitter”标签嵌入多个 DIV 语句或表中造成的。出于某种原因,IE7 不喜欢这样。
祝你好运!
I know that this is an old question, but I ran into a similar thing today and I wanted to post it out for others in case you experience this issue. This is likely being caused by your "column_twitter" tag being embedded in multiple DIV statements or in a table. IE7 doesn't like this for some reason.
Good Luck!