开发者

Why is my Ajax code not working in IE8?

My Ajax code does not work in IE8 but it works in Firefox. I have tried a couple different ways that people posted on the internet but none of them seem to work.

Here is my code that works, just not in IE8:

function populatematerial(str)
{
    if (str=="") {
      document.getElementById("txtHint").innerHTML="";
      return;
    }

    var xmlHttp = null;

    if (window.XMLHttpRequest) {
     // IE7+, Firefox, Chrome, Opera,开发者_如何学Go Safari
      xmlhttp=new XMLHttpRequest();
    }

    else{
     // IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function()
    {
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
      }
    }

    xmlhttp.open("GET","GetMySQLData.php?q="+str,true);
    xmlhttp.send();
}

In the PHP file it just gets data from the MySQL database to populate a new select method.


Remove this part of the if statement: && xmlhttp.status==200 and you should be good (this seems to be a bug in IE)


What type of error you are getting.. post the error message...

also make sure that there is no javascript function is returned from the php page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜