Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using ajax to call server side php function for form submition. It seems to be xmlhttpresponse==4 is not set when using type="submit" for submit button. here is my code

Javascript function
C#
function gotoLogin(form){

                email =form.email.value;
                password =form.password.value;

//
                if(email!='' && password!='')
                {
                    var xmlhttp;
                    if (window.XMLHttpRequest)
                    {// code for IE7+, Firefox, Chrome, Opera, Safari

                        xmlhttp=new XMLHttpRequest();
                    }
                    else
                    {// code for IE6, IE5
                        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    xmlhttp.onreadystatechange=function()
                    {

                        if (xmlhttp.readyState==4 && xmlhttp.status==200)
                        {

                            document.getElementById("myDiv").innerHTML=xmlhttp.responseText;

                        }
                    }

                    xmlhttp.open("GET","http://localhost/mvc/login/testing/"+email+"/"+password,true);
                    xmlhttp.send();
                }

}


function gotoLogin invokes as follows
HTML
<input type="submit" name="Submit" value="Log in" onclick="gotoLogin(this.form)"/>


If anyone has any clue to correct this please let me know.
thanks.
Posted
Updated 8-Jun-12 22:35pm
v2
Comments
krumia 9-Jun-12 4:44am    
Additional note: Are you kidding me? You're sending the password in the URL?

1 solution

On what grounds do you say readyState==4 is not set?

For all I can see, there are two conditions in your if condition.

Try following and see what's happening.
JavaScript
if (xmlHttp.readyState == 4) {
    alert('readyState==4, status==' + xmlHttp.status);

    if (xmlHttp.status == 200) {
        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
}


And see what happens.
 
Share this answer
 
Comments
swsachi 9-Jun-12 6:45am    
Thank you very for your concern. I ckecked out your code fragment. But "alert" is not working
krumia 9-Jun-12 9:08am    
What do you mean by alert not working?
Okay, does your function gets called at all?
Did you try to debug the code?
Did you try putting some alert() calls in the beginning of the getLogin function, and at the beginning of each if block? Are you trying to debug your code using us?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900