开发者

Ajax doesn't work on remote server

开发者 https://www.devze.com 2023-01-02 08:46 出处:网络
when I Implemented chattingFunction , I use Ajax to send messagesbetween fileto开发者_Go百科 another .

when I Implemented chatting Function , I use Ajax to send messages between file to开发者_Go百科 another .

so , it is working well on local host .

but , when I upload it in to remote server it doesn't work.

can U tell me ,why ? is an Ajax need Special configuration ?

Ajax code :

function Ajax_Send(GP,URL,PARAMETERS,RESPONSEFUNCTION){
    var xmlhttp
    try{
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch(e) {
        try{
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
        }
        catch(e){
            try{
                xmlhttp=new XMLHttpRequest()
            }
            catch(e){
                alert("Your Browser Does Not Support AJAX")
            }
        }
    }

    err=""
    if (GP==undefined) err="GP "
    if (URL==undefined) err +="URL "
    if (PARAMETERS==undefined) err+="PARAMETERS"
    if (err!=""){alert("Missing Identifier(s)\n\n"+err);return false;}

    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState == 4){
            if (RESPONSEFUNCTION=="") return false;
            eval(RESPONSEFUNCTION(xmlhttp.responseText))
        }
    }

    if (GP=="GET"){
        URL+="?"+PARAMETERS
        xmlhttp.open("GET",URL,true)
        xmlhttp.send(null)
    }

    if (GP="POST"){
        PARAMETERS=encodeURI(PARAMETERS)
        xmlhttp.open("POST",URL,true)
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
        xmlhttp.setRequestHeader("Content-length",PARAMETERS.length)
        xmlhttp.setRequestHeader("Connection", "close")
        xmlhttp.send(PARAMETERS)
    }       
}


Two points really,

Firstly, If the URL is on a different domain, default security model in your browser might stop that working. Secondly, have a look at JQuery, this bulk of code would be reduced to 2 or 3 lines.

Have a look here: http://docs.jquery.com/Tutorials

0

精彩评论

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