【发布时间】:2012-09-10 06:00:01
【问题描述】:
我有一个表格:
<form id="orderForm" onsubmit="return prepareOrder(this);" action='@ConfigurationManager.AppSettings["EpayLogonUrl"]' method="POST">
还有prepareOrder函数:
function prepareOrder(form) {
$('.wizard_next_step').attr('disabled', 'disabled');
$('.wizard_next_step').addClass('disabled');
$('.wizard_prev_step').attr('disabled', 'disabled');
$('.wizard_prev_step').addClass('disabled');
$.ajax({
type: 'POST',
url: '/Pay/CreateOrder',
success: function (response) {
if (response.IsSuccess) {
alert('2');
$("input[type=hidden][name=Signed_Order_B64]").val(response.Message);
} else {
alert('1');
toastr.options.timeOut = 10000;
toastr.info(response.Message);
return false;
}
},
error: function () {
return false;
},
async: false
});
}
当IsSuccess 等于 false 时提交不会停止的问题。为了测试,我正确插入警报和警报显示(1),但无论如何都要提交表单。哪里出了问题?
【问题讨论】:
-
而不是
return false;执行returnVal = false;并且,在prepareOrder的末尾,执行return returnVal == false ? false : true; -
@goldenparrot - 你为什么不最后做
return returnVal;? -
@goldenparrot:你为什么要这么做?只需
return false; -
@WesleyMurch - 这里的想法是根据(同步)Ajax 响应有条件地停止提交。 (大概需要某种预先验证,尽管我不会那样编码。)
-
@nnnnnn:我读错了整件事,我累了,去睡觉吧;)祝你好运
user1260827
标签: javascript jquery forms