我想在同一页面的正下方直接在模式中显示成功消息,而不重定向到新页面。 所以我这样做了,但是为什么不起作用?
HTML代码
<html>
<head>
<meta charset="UTF-8">
<title>essai</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<form form id="form1">
donnee1:<input type="text" name="donnee1"/>
<input type="submit" vatue="envoyer">
</form>
此div中呈现的成功消息的结果
<div id="result"></div>
<script>
$(document).ready(function() {
$("#form1").submit(function(event) {
event.preventDefault();
$("#result").html('');
var values = $(this).serialize();
var ajaxRequest= $.ajax({
url: "php.php",
type: "post",
data: values
});
ajaxRequest.done(function (response, textStatus, jqXHR){
$("#result").html('Submitted successfully');
});
ajaxRequest.fail(function (){
$("#result").html('There is error while submit');
});
});
</script>