我已創建的HTML形式並且處理經由一個PHP頁中的數據,我想接收/顯示同一頁(索引的「插入/失敗」通知。 html)。我使用的是javascript,ajax和jquery。數據在數據庫中更新,但我在process.php頁面上獲得結果。我想在index.html頁面本身上插入結果通知。形式使用javascript,AJAX PHP,jquery的
的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頁面的代碼。 –