views:

104

answers:

1

Hello .

when I Implemented chatting Function , I use Ajax to send messages between file to 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)
    }       
}
+2  A: 

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

Russ C
thanks for U response .but , can U correct the above code please .depend on this problem .
Nina