ajax脚本使用firefox而不是ie6

时间:2021-09-29 20:35:47

i have this ajax function working well in firefox and not in ie6 are there some specific issues for ie? the error is on ths line

我有这个ajax功能在firefox中运行良好而不是ie6是否有一些具体问题呢?错误就在线上

document.getElementById(containerid).innerHTML=page_request.responseText

here is the full code i'm using

这是我正在使用的完整代码

  var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch (e){
            try{
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e){}
        }
    }
    else
        return false
    page_request.onreadystatechange=function(){
        loadpage(page_request, containerid)
    }
    if (bustcachevar) //if bust caching of external page
        bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
    page_request.open('GET', url+bustcacheparameter, true)
    page_request.send(null)
}

function loadpage(page_request, containerid){
    if (page_request.readyState == 4 && (page_request.status==200 || 

window.location.href.indexOf("http")==-1))
////////////////////// here is the error line pointed by ie debugger/////////
            document.getElementById(containerid).innerHTML=page_request.responseText
////////////////////////////// 
}

thanks for your answers

谢谢你的回答

1 个解决方案

#1


1  

Try using something like this - or checking out jQuery

尝试使用这样的东西 - 或检查jQuery

function isIE(){return/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent);}

function parseFile(filename)
{
    try
    {
        if(isIE())
        {var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
        else
        {var xmlhttp=false;}
        if(!xmlhttp&&typeof XMLHttpRequest!='undefined')
        {
            try
            {xmlhttp=new XMLHttpRequest();}
            catch(e)
            {xmlhttp=false;}
        }
        if(!xmlhttp&&window.createRequest)
        {
            try
            {xmlhttp=window.createRequest();}
            catch(e)
            {xmlhttp=false;}
        }

        xmlhttp.open("GET",filename);
        xmlhttp.onreadystatechange=function()
        {
        if(xmlhttp.readyState==4)
        {   
            return xmlhttp.responseText;
        }
    }
    xmlhttp.send(null);
}
catch(e)
{
    alert(e);
}
}

#1


1  

Try using something like this - or checking out jQuery

尝试使用这样的东西 - 或检查jQuery

function isIE(){return/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent);}

function parseFile(filename)
{
    try
    {
        if(isIE())
        {var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
        else
        {var xmlhttp=false;}
        if(!xmlhttp&&typeof XMLHttpRequest!='undefined')
        {
            try
            {xmlhttp=new XMLHttpRequest();}
            catch(e)
            {xmlhttp=false;}
        }
        if(!xmlhttp&&window.createRequest)
        {
            try
            {xmlhttp=window.createRequest();}
            catch(e)
            {xmlhttp=false;}
        }

        xmlhttp.open("GET",filename);
        xmlhttp.onreadystatechange=function()
        {
        if(xmlhttp.readyState==4)
        {   
            return xmlhttp.responseText;
        }
    }
    xmlhttp.send(null);
}
catch(e)
{
    alert(e);
}
}