通过XMLHttpRequest提交表单
Form Submission via XMLHttpRequest
我想使用XMLHttpRequest来获取远程PHP文件的响应并将其显示在我的页面上。
当然,我的问题是:表单的数据没有提交到那个远程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();
}
您必须通过在函数调用xmlhttp.open("POST","accountcreation.php",true);
中指定的URL发送一些数据
可以通过以下链接查看处理相同类型问题的帖子http://www.csnotes32.com/2014/09/sample-code-for-check-availability.html
相关文章:
- HTML表单提交时未执行外部函数
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 将图像上传ajax与表单提交ajax相结合
- Javascript无法处理表单提交
- 如何在我的情况下禁用表单提交
- 加载后的页面与ajax表单提交不起作用
- angularjs-控制器在表单提交时未调用
- 禁用带有字符白名单的表单提交
- 如何使用Google Analytics跟踪表单提交
- 使用javascript将表单提交到iframe目标中
- e.preventDefault在表单提交时被忽略
- AngularJS JQuery Ajax表单提交等效
- JavaScript表单提交帮助
- PHP表单提交和重定向
- 当所有输入文本字段都为空时,禁止表单提交,但当jquery中的任何字段不为空时允许提交
- setTimeOut AFTER jQuery表单提交
- 从函数中选择要触发表单提交的正确元素
- JavaScript表单提交没有't fire asp服务器端点击功能的提交按钮
- 表单提交问题,如何在我的URL末尾获得ID的值
- Javascript使用Confirm取消表单提交