Question

I go this AJAX code that worked fine, but when I moved it to a new file it stopped working. I managed to find out that the readystate isn't 4 and status isn't 200. The code was given to my in class by the teacher. It worked find until I made new file.

<script type = "text/javascript">
var request = false;

if (window.XMLHttpRequest)
request = new XMLHttpRequest();
 else if (window.AciveXObject)
request = new ActiveXObject("Microsoft.XMLHTTP");


  function login(PhpFile,divId,frm)
  {
if (request)
{
    var obj = document.getElementById(divId);
    request.open("POST",PhpFile);
    //setting the header
    request.setRequestHeader('Content-Type','application/x-www-form-   urlencoded');

    request.onreadystatechange = function()
    {   
        if (request.readyState == 4 &&
                request.status == 200){
            obj.innerHTML =request.responseText;
        }
        else
        {
         alert("here");
        }
    }

    request.send("log="+frm.log.value+"&pwd="+frm.pwd.value);
} 
}


</script>
Was it helpful?

Solution

if you alert(request.responseText) in that else case, that may give you more information

OTHER TIPS

'application/x-www-form-   urlencoded'

should be

'application/x-www-form-urlencoded'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top