Cha*_*ell 2 ajax asp.net-mvc jquery
我似乎无法弄清楚如何使用Ajax从jquery ui按钮函数提交表单.
这是我的脚本,通过传统方式提交表单
$('#contact-form').dialog({
modal: true,
autoOpen: false,
buttons: {
Cancel: function () {
$(this).dialog('close');
},
Ok: function () {
$('form#contactUs').submit();
$(this).dialog('destroy');
}
}
});
$('#contact-us').click(function () {
$('#contact-form').dialog('open');
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
这是我的表格
<div id="contact-form" class="hidden" title="Online Request Form">
<form action="/Main/Contact/contactUs" method="post">
<div>
<label for="Name">Name</label><br />
<input name="Name" /><br />
<label for="PhoneNumber">Phone Number</label><br />
<input name="PhoneNumber" /><br />
<label for="EmailAddress">Email Address</label><br />
<input name="EmailAddress" /><br />
<label for="Question">Question or Comment</label><br />
<textarea name="Question"></textarea><br />
<label for="Security">What color is an orange?</label><br />
<input name="Security" />
<noscript>
<input type="submit" name="submit" value="Ok" />
</noscript>
</div>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
如何更改此项以通过Ajax提交链接以便我可以显示成功消息?
这可能就足够了:
$("#contact-form form").submit(function(e) {
e.preventDefault();
$.post( $(this).attr('action'), $(this).serialize(),
function(resp) {
if(resp == "success") {
alert('Submission was successful');
} else {
// something else
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
简要说明:
进一步阅读:
| 归档时间: |
|
| 查看次数: |
1481 次 |
| 最近记录: |