Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.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
为什么在javascript/AJAX中的xhr.onreadystatechange()中没有“form.submit()”响应_Javascript_Php_Ajax - Fatal编程技术网

为什么在javascript/AJAX中的xhr.onreadystatechange()中没有“form.submit()”响应

为什么在javascript/AJAX中的xhr.onreadystatechange()中没有“form.submit()”响应,javascript,php,ajax,Javascript,Php,Ajax,form.submit函数无法响应xhr.onreadystatechange 这是我的登录表单: <form action="user_home.php" method="post" id="loginForm" > <tr> <td colspan=2>Members log in here:</td> <tr> <td>Username:</td> <td&g

form.submit函数无法响应xhr.onreadystatechange

这是我的登录表单:

<form action="user_home.php" method="post" id="loginForm" >
   <tr>
     <td colspan=2>Members log in here:</td>
   <tr>
     <td>Username:</td>
     <td><input type='text' name='username' id='username' /></td></tr>
   <tr>
     <td>Password:</td>
     <td><input type='password' name='password' id="password" /></td></tr>
   <tr>
     <td colspan=2 align='center'>
     <input type="submit" name="submit" id="submit"  value= "Login" /></td></tr>
</form>
<script src="forLogin.js"></script>
在javascript中

xhr.onreadystatechange = function() {
  if (xhr.readyState == 4) {
    if ((xhr.status >= 200 && xhr.status < 300) || (xhr.status == 304)) {
      if (xhr.responseText == 'VALID') {

        alert(xhr.responseText); //this works

        var form = document.getElementById('loginForm');
        form.submit(); // it doesnt work!!!
      } else {
        var message = '<h2>Error!</h2><p>The following Error(s) occured: <ul>';
        message += '<li class="error">Invalid Username Password combinations!</li>';
        showErrorMessage(message);
      }
      xhr = null;
    }
  }
};
当我的ajax函数send->echo'VALID'时; 我收到警报,但没有重定向。为什么? 有人知道吗?

你可以试试

   document.getElementById("loginForm").submit();
而不是

                var form = document.getElementById('loginForm');

                form.submit();// it doesnt work!!!
问题就在这里,

<input type='text' name='username' id='username' /> 
 <input type='password' name='password' id="password" />
将其更改为:-

    <td><input name='username' id='username'  type='text'  >
   <td><input name='password' id="password" type='password'  >

现在可以工作了…

为什么这会有什么不同?相同的结果…没有导航何时执行ajax调用?是否在表单提交上?您在哪里提交XHR请求?这是如何触发的?我只给出了代码的一部分,我知道代码发生在哪里。但是为什么人们会对我的问题做出回应!!请看我的答案,当我更改html标记中的名称和id字段时,我得到了正确的答案。任何一个犯这种错误的人都可以得到这个…然后也可以-ve mark:-@我只是看到你改变了属性的顺序,并在最后删除了/,但我认为这不是问题的原因。