我通过使用 JQuery 的帖子调用提交表单而不离开我的页面。
提交后,我想用其中的表单替换 div,并带有感谢信息。问题是在我提交之前显示消息而不是替换,下面是我的代码。
$(document).ready(function() {
//When the form with id="myform" is submitted...
$("#myform").submit(function() {
//Send the serialized data to mailer.php.
$.post("mailer.php", $("#myform").serialize(),
//Take our repsonse, and replace whatever is in the "formResponse"
//div with it.
function(data) {
$("#formResponse").html(data);
}
);
return false;
});
});
和 HTML
<div data-role="content">
<form id="myform">
<div data-role="fieldcontain">
<label for="name">Name:</label>
<input type="text" name="name" id="name" value="" />
</div>
<div data-role="fieldcontain">
<label for="email">Email:</label>
<input type="email" name="email" id="email" value="" />
</div>
<div data-role="fieldcontain">
<label for="company">Company Name:</label>
<input type="text" name="company" id="company" value="" />
</div>
<input type="submit" name="submit" value="Submit" data-icon="star" data-theme="b" />
</form>
</div>
<div data-role="content" div id="formResponse">
thank you, your quote has been received and you will hear back from us shortly.
</div>