【发布时间】:2015-11-09 15:48:53
【问题描述】:
我创建了一个带有 HTML 的表单并通过 PHP 页面处理数据,我想在同一页面上接收/显示“inserted/failed”通知(index.html)。 html)。我正在使用 javascript、ajax 和 jquery。数据库中的数据已更新,但我在 process.php 页面上获得了结果。我想在 index.html 页面本身上插入结果通知。
index.html
<html>
<head><title>Registration form</title></head>
<body>
<form id="myForm" action="process.php" method="POST">
Username: <input type="text" name="username"> <br />
Password: <input type="password" name="pass"> <br />
First name: <input type="text" name="fname"> <br />
Last name: <input type="text" name="lname"> <br />
<button id="submit" name="submit">Register</button>
</form>
<div id="ack">Acknowledge</div>
<script type="text/JavaScript" src="script/jquery-1.11.3.min.js"></script>
<script type="text/JavaScript" src="script/my_script.js"></script>
</body>
</html>
my_script.js
$("#submit").click( function(){
$.post( $("#myForm").attr("action"),
$("#myForm :input").serializeArray(),
function(info){
$("#ack").empty();
$("#ack").html(info);
clear();
});
$("#myForm").submit( function(){
return false;
});
});
function clear(){
$("#myForm:input").each( function()){
$(this).val("");
}
}
【问题讨论】:
-
粘贴process.php页面的代码
标签: javascript php jquery html ajax