我通過post調用提交表單而不離開我的頁面使用JQuery。表單提交後使用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>
@丹 - 我認爲這是有道理的... *「我提交後,我想用它的形式替換與感謝信息的形式。」* –
請提高您的接受程度 – sakhunzai
我會在一分鐘內接受我喜歡Nelsons的回答,並正在努力通過它,仍然有一個小問題,但幾乎得到它。 –