Matt
Matt

Reputation: 55

Ajax responseText Null in Internet Explorer?

I have some simple ajax code. All I want to do is load a php page into a container but in internet explorer I get the error: SCRIPT5007: Unable to set value of the property 'innerHTML': object is null or undefined. Which means that internet explorer sees xmlhttp.responseText as null. It does this with any way I have tried to get the ResponseText. Heres my code:

 function changeSort(type, order)
    {
    var xmlhttp;
    var container = document.getElementById("content");

    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)
        {
      container.innerHTML = xmlhttp.responseText; //Error Line
        }
      }
xmlhttp.open("GET","Scripts/tag.php?sort=ASC&&tag=All%20Games&&type="+type,true);
xmlhttp.send();
}

Any Ideas?

Upvotes: 2

Views: 6155

Answers (1)

bobince
bobince

Reputation: 536567

Unable to set value of the property 'innerHTML': object is null or undefined. Which means that internet explorer sees xmlhttp.responseText as null.

No, it means that Internet Explorer sees container as null. If you'd tried to set a null value on innerHTML, it would have been coerced to the string 'null'.

Probably IE couldn't find any element with ID content in the document at the time changeSort was called.

"Scripts/tag.php?sort=ASC&&tag=All%20Games&&type="+type

Are you sure you mean double-ampersand?

Upvotes: 1

Related Questions