PHP没有使用XMLHttpRequest从HTML接收正确的数据

时间:2014-10-31 22:36:28

标签: javascript php xmlhttprequest

以下函数应该发送数据做一个php脚本。运行php脚本时,找不到索引_ $ POST [“sessionID”]。

function logout(){
  var logoutRequest = new XMLHttpRequest();
  logoutRequest.open("POST", "server/logout.php", false);
  logoutRequest.setRequestHeader('Conent-type', 'application/x-www-form-urlencoded');
  logoutRequest.onreadystatechange = function () {
    if(logoutRequest.readyState == 4 && logoutRequest.status == 200) {
        sessionID = logoutRequest.responseText;
        console.log(sessionID);
    }
  }
  logoutRequest.send("sessionID=" + login_form.elements["sessionID"].value);
}


  <form name="login_form" method="post" id="login-form" onsubmit="submitForm(); return false;">
    <input type="text" name="username" id="username" placeholder="Username" required></input>
    <input type="password" name="password" id="password" placeholder="Password" required></input>
    <input type="submit" value="Log in" class="btn" id="submit-button"></input>
    <input id="sessionID" type="hidden" value="16"></input>
  </form>

0 个答案:

没有答案