当使用类型"submit"时,不执行xmlhttpresonse = 4. [英] xmlhttpresonse=4 is not executed when using type "submit"

查看:54
本文介绍了当使用类型"submit"时,不执行xmlhttpresonse = 4.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ajax调用服务器端php函数进行表单提交.使用type ="submit"作为提交按钮时,似乎未设置xmlhttpresponse == 4.这是我的代码

JavaScript函数

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

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();
                }

}



函数gotoLogin调用如下



function gotoLogin invokes as follows

<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.

推荐答案

您出于什么原因说未设置readyState == 4?

据我所知,您的if条件中有两个条件.

尝试关注并查看发生了什么.
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.
if (xmlHttp.readyState == 4) {
    alert('readyState==4, status==' + xmlHttp.status);

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



看看会发生什么.



And see what happens.


这篇关于当使用类型"submit"时,不执行xmlhttpresonse = 4.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆