日期:2014-05-18  浏览次数:20417 次

XMLHttpRequest在IE7中如何操作?
由于IE7开始支持XMLHttpRequest,我在IE7中试验了一下,但是就是不成功。由于IE7使用的是“new   XMLHttpRequest()”,IE6和IE5使用的是“new   ActiveXObject( "Microsoft.XMLHTTP ")”,这段代码在IE6和IE5中没问题。我使用XMLHttpRequest是想支持其他浏览器。请问下面的代码问题出在哪?
代码如下:
<script   language= "javascript ">
    var   xmlHttp;
    try{
        if(window.XMLHttpRequest)
        {
            //IE7,mozilla
            xmlHttp=new   XMLHttpRequest();
        }
        else
        {
            //IE6,I5
            xmlHttp=new   ActiveXObject( "Microsoft.XMLHTTP ");
        }
    }
    catch(e)
    {
          alert( "对不起你的浏览器不支持XMLHTTP,原因 "+e.description+ "   请启用ActiveX或升级 ");
      }

      function   sendAJAX(inputcode)
      {
          xmlHttp.open( "POST ", "Logonservice.aspx?inputcode= "+inputcode,true);
          xmlHttp.onreadystatechange=ServerProcess;
          xmlHttp.send(null);
      }
     
      function   ServerProcess()
      {
            //alert( "readystate= "+xmlHttp.readystate+ ",status= "+xmlHttp.readystate);
            if   (xmlHttp.readystate==4   ||   xmlHttp.readystate== 'complete ')
            {
document.all.item( "user_name ").innerText   =   xmlHttp.responseText;
            }
        }
</script>        
---------------------------------------
在函数ServerProcess中,我使用alert测试时,readystate和status都等于undefined。

------解决方案--------------------
<script language= "javascript ">
var xmlHttp;
try{
if(window.XMLHttpRequest)
{
//IE7,mozilla
xmlHttp=new XMLHttpRequest();
}
else
{
//IE6,I5
try
{
xmlHttp=new ActiveXObject( "Microsoft.XMLHTTP ");
}
catch(e)
{
xmlHttp=new ActiveXObject( "Msxml2.XMLHTTP "); }
}
}
catch(e)
{
alert( "对不起你的浏览器不支持XMLHTTP,原因 "+e.description+ " 请启用ActiveX或升级 ");
}


------解决方案--------------------
没有IE7.办法调试!
------解决方案--------------------
给IE7打一下补丁,不打补丁IE7有些问题。不一定是你程序的问题。