通过XMLHttpRequest提交表单
问题描述:
我想使用XMLHttpRequest来获取远程PHP文件的响应并将其显示在我的页面上。通过XMLHttpRequest提交表单
我的问题当然是:表单的数据没有被提交到远程PHP页面。
我该如何做到这一点? 谢谢。
<form name="creation" action="" method="post">
E-mail:
<input required type="text" name="emailCreation" onchange="emailValidate();"
onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();">
<span id="emailRegexJavascriptResponse"></span>
<br>
Username: <input required type="text" name="userCreation" onchange="userValidate();"
onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();">
<span id="userRegexJavascriptResponse"></span>
<br>
Password: <input required type="text" name="passwordCreation" onchange="passwordValidate();"
onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();">
<span id="passwordJavascriptResponse"></span>
<br>
<input type="button" value="Submit" onclick="creationResult();">
<div id="here"></div><div id="here2"></div>
<!-- End -->
<script type="text/javascript">
function creationResult() {
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("here").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","accountcreation.php",true);
xmlhttp.send();
}
答
你要发送通过URL是否指定函数调用的一些数据xmlhttp.open("POST","accountcreation.php",true);
它处理同一类型的问题可以通过跟随着链接 http://www.csnotes32.com/2014/09/sample-code-for-check-availability.html
可以看到一个帖子