AJAX document.getElementById (). Internal HTML issue with IE?
Before someone said that I didn't read, I can say that I read almost everything related to my question. But I couldn't find an answer. So, I have a simple AJAX script that loads my external file inside a predefined div. This is the code of these scripts:
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 fine in every browser I test (FF, Opera, Chrome, Safari), but inside IE7 don't want to embed my external php file in a predefined div. It always remains the default text that I click inside the div ... And I think the problem is with this line:
document.getElementById("column_twitter").innerHTML=xmlHttp.responseText;
So, any suggestions to fix this for IE (7 and up)?
source to share
I think you are better off using a javascript framework like jQuery , which allows you to focus on implementing your functionality rather than browser compatibility and low-level networking. Using jQuery you can simply do:
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>
<script type="text/javascript">
$.get( '../includes/home/twitter.php', function(data) {
$('#column_twitter').html( data );
});
</script>
source to share
I know this is an old question, but I ran into a similar case today and I wanted to post it for others if you are facing this problem. This is probably because the "column_twitter" tag is embedded in multiple DIV statements or in a table. IE7 doesn't like it for some reason.
Good luck!
source to share