Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我能';在ajax检索函数之后是否自动运行JS函数? $(文档).ready(函数(){ $(“#按钮1”)。单击(函数(){ if(document.getElementById(“hidValid”).value==“正确的用户名和密码”){ parent.result.location.href=“user.php”; window.location.href=“welcomeuser.php”; } }); }); 函数验证\使用\传递(用户名、密码){ var loginUserID=document.getElementById(“loginUserID”).value; var passUserID=document.getElementById(“passUserID”).value; 如果(loginUserID==“”){ 警报(“无效用户名/密码”); }else if(passUserID==“”){ 警报(“无效用户名/密码”); } if(loginUserID==“admin”&&passUserID==“admin”){ parent.result.location.href=“account.php”; window.location.href=“welcome.php”; }否则{ var-xmlhttp; /*if(username.length==0 | | password.length==0){ document.getElementById(“validateText”).value=“输入用户名/密码”; 返回; }*/ if(window.XMLHttpRequest) {//IE7+、Firefox、Chrome、Opera、Safari的代码 xmlhttp=新的XMLHttpRequest(); } 其他的 {//IE6、IE5的代码 xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”); } xmlhttp.onreadystatechange=函数() { if(xmlhttp.readyState==4&&xmlhttp.status==200) { document.getElementById(“validateText”).innerHTML=xmlhttp.responseText; document.getElementById(“hidValid”).value=xmlhttp.responseText; } } xmlhttp.open(“GET”、“validateUsePass.php?username=“+username+”&password=“+password,true”); xmlhttp.send(); }_Php_Javascript_Jquery_Ajax - Fatal编程技术网

为什么我能';在ajax检索函数之后是否自动运行JS函数? $(文档).ready(函数(){ $(“#按钮1”)。单击(函数(){ if(document.getElementById(“hidValid”).value==“正确的用户名和密码”){ parent.result.location.href=“user.php”; window.location.href=“welcomeuser.php”; } }); }); 函数验证\使用\传递(用户名、密码){ var loginUserID=document.getElementById(“loginUserID”).value; var passUserID=document.getElementById(“passUserID”).value; 如果(loginUserID==“”){ 警报(“无效用户名/密码”); }else if(passUserID==“”){ 警报(“无效用户名/密码”); } if(loginUserID==“admin”&&passUserID==“admin”){ parent.result.location.href=“account.php”; window.location.href=“welcome.php”; }否则{ var-xmlhttp; /*if(username.length==0 | | password.length==0){ document.getElementById(“validateText”).value=“输入用户名/密码”; 返回; }*/ if(window.XMLHttpRequest) {//IE7+、Firefox、Chrome、Opera、Safari的代码 xmlhttp=新的XMLHttpRequest(); } 其他的 {//IE6、IE5的代码 xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”); } xmlhttp.onreadystatechange=函数() { if(xmlhttp.readyState==4&&xmlhttp.status==200) { document.getElementById(“validateText”).innerHTML=xmlhttp.responseText; document.getElementById(“hidValid”).value=xmlhttp.responseText; } } xmlhttp.open(“GET”、“validateUsePass.php?username=“+username+”&password=“+password,true”); xmlhttp.send(); }

为什么我能';在ajax检索函数之后是否自动运行JS函数? $(文档).ready(函数(){ $(“#按钮1”)。单击(函数(){ if(document.getElementById(“hidValid”).value==“正确的用户名和密码”){ parent.result.location.href=“user.php”; window.location.href=“welcomeuser.php”; } }); }); 函数验证\使用\传递(用户名、密码){ var loginUserID=document.getElementById(“loginUserID”).value; var passUserID=document.getElementById(“passUserID”).value; 如果(loginUserID==“”){ 警报(“无效用户名/密码”); }else if(passUserID==“”){ 警报(“无效用户名/密码”); } if(loginUserID==“admin”&&passUserID==“admin”){ parent.result.location.href=“account.php”; window.location.href=“welcome.php”; }否则{ var-xmlhttp; /*if(username.length==0 | | password.length==0){ document.getElementById(“validateText”).value=“输入用户名/密码”; 返回; }*/ if(window.XMLHttpRequest) {//IE7+、Firefox、Chrome、Opera、Safari的代码 xmlhttp=新的XMLHttpRequest(); } 其他的 {//IE6、IE5的代码 xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”); } xmlhttp.onreadystatechange=函数() { if(xmlhttp.readyState==4&&xmlhttp.status==200) { document.getElementById(“validateText”).innerHTML=xmlhttp.responseText; document.getElementById(“hidValid”).value=xmlhttp.responseText; } } xmlhttp.open(“GET”、“validateUsePass.php?username=“+username+”&password=“+password,true”); xmlhttp.send(); },php,javascript,jquery,ajax,Php,Javascript,Jquery,Ajax,} 问题是我似乎无法在“xmlhttp.send();”之后运行函数。 因此,当我登录时,我需要按2x按钮来运行JS函数 第一次按下按钮将从PHP检索数据,然后第二次按下按钮将运行JS函数。尝试以下操作: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type=

}

问题是我似乎无法在“xmlhttp.send();”之后运行函数。 因此,当我登录时,我需要按2x按钮来运行JS函数

第一次按下按钮将从PHP检索数据,然后第二次按下按钮将运行JS函数。

尝试以下操作:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $("#button1").click(function(){
 if(document.getElementById("hidValid").value == "Correct Username & Password"){
             parent.result.location.href="user.php";
            window.location.href="welcomeuser.php";
         }
      });
    });
    </script>
    <script type="text/javascript">
    function validate_use_pass(username,password){
        var loginUserID = document.getElementById("loginUserID").value;

        var passUserID = document.getElementById("passUserID").value;

        if(loginUserID == ""){
            alert("Invalid Username/Password.");
        }else if(passUserID == ""){
            alert("Invalid Username/Password.");
        }
        if(loginUserID == "admin" && passUserID =="admin" ){
    parent.result.location.href="account.php";
    window.location.href="welcome.php";
        }else{
            var xmlhttp;
            /*if(username.length==0 || password.length==0){
                document.getElementById("validateText").value="Enter Username/Password";
        return;
    }*/
    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("validateText").innerHTML=xmlhttp.responseText;
        document.getElementById("hidValid").value=xmlhttp.responseText;
        }
      }

    xmlhttp.open("GET","validateUsePass.php?username="+username+"&password="+password ,true);
    xmlhttp.send();
}
试试这个:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $("#button1").click(function(){
 if(document.getElementById("hidValid").value == "Correct Username & Password"){
             parent.result.location.href="user.php";
            window.location.href="welcomeuser.php";
         }
      });
    });
    </script>
    <script type="text/javascript">
    function validate_use_pass(username,password){
        var loginUserID = document.getElementById("loginUserID").value;

        var passUserID = document.getElementById("passUserID").value;

        if(loginUserID == ""){
            alert("Invalid Username/Password.");
        }else if(passUserID == ""){
            alert("Invalid Username/Password.");
        }
        if(loginUserID == "admin" && passUserID =="admin" ){
    parent.result.location.href="account.php";
    window.location.href="welcome.php";
        }else{
            var xmlhttp;
            /*if(username.length==0 || password.length==0){
                document.getElementById("validateText").value="Enter Username/Password";
        return;
    }*/
    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("validateText").innerHTML=xmlhttp.responseText;
        document.getElementById("hidValid").value=xmlhttp.responseText;
        }
      }

    xmlhttp.open("GET","validateUsePass.php?username="+username+"&password="+password ,true);
    xmlhttp.send();
}

将您的附加函数放在这里:
xmlhttp.onreadystatechange
既然您已经在使用jquery,那么使用jquery的一个ajax函数也会容易得多;它会将代码缩减一半,同时可能解决您的问题。将您的附加函数放在这里:
xmlhttp.onreadystatechange
由于您已经在使用jquery,使用jquery的一个ajax函数也会容易得多;它将把你的代码缩减一半,并可能同时解决你的问题。