我是 Ajax 和 Js 的初學者,所以我希望我的按鈕呼叫我的操作方法,所以這是我的腳本:
<div class="buttons">
<input type="button" class="btn btn-success" id="PassCode" value="????? ????? ????">
</div>
$(document).ready(function () {
$("#$PassCode").click(function (e) {
var form = this;
$.ajax({
url: '@Url.Action("RenderOnetimePassword", "Customer")',
type: 'POST',
data: $(form).serialize(),
beforeSend: function () {
$("#Password").addClass("loading");
},
success: function (response) {
if (!response.success)
showError(response.message, response.captcha_string);
else if (response.url)
window.location.href = response.url;
else if (response.update_section)
$("." response.update_section.name).html(response.update_section.html);
},
complete: function () {
$("#Password").removeClass("loading");
},
error: function (error) {
alert("@T("Account.ErrorNotification")");
}
});
}
});
在客戶控制器中我有這個方法:
public ActionResult RenderOnetimePassword (SMSCodeVerificationModel model)
{
// some code here
}
我想呼叫我的操作,但是當我單擊按鈕時,它不起作用。
uj5u.com熱心網友回復:
嗨,歡迎來到前端世界!
你需要學習更多關于ajax和jquery 的函式, 所以試試這個
$(document).on('click', function () {
$("#PassCode").click(function () {
var form = this;
$.ajax({
cache: false,
url:'@Url.Action("RenderOnetimePassword", "Customer")',
data: $(form).serialize(),
type: 'post',
beforeSend: function () {
$("#Password").addClass("loading");
},
success: function (response) {
if (!response.success)
showError(response.message, response.captcha_string);
else if (response.url)
window.location.href = response.url;
else if (response.update_section)
$("." response.update_section.name).html(response.update_section.html);
},
complete: function () {
$("#Password").removeClass("loading");
},
error: function (error) {
alert("@T("Account.ErrorNotification")");
}
});
});
});
我希望它可以解決您的問題:)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/373267.html
標籤:查询 阿贾克斯 asp.net-mvc asp.net-ajax
上一篇:如何在$.get中發送引數?
