我有一个想要手动或以编程方式提交的页面。但在允许提交页面之前,需要启动一个函数 [create_impi_num(x)] 以在该函数中使用 "$.post('" 存储数据。
问题:如果我将 submit(function(e) 设置为 return false,则调用函数并存储我的数据。如果我将 return 设置为 true,则我的表单已发布,但我的函数被忽略。
这是我的代码:
$('#pay-and-complete').submit(function(e) {
var ok = confirm('Do you really want to save your data?');
if (ok) {
var CanPay;
var igroupid = Number($('#hid-step3-entryid').val());
//function here
create_impi_num($('#hid-parc-id').val(),$('#hid-step3-entryid').val());
return true;
}
else {
//Prevent the submit event and remain on the screen
create_impi_num($('#hid-parc-id').val(),$('#hid-step3-entryid').val());
e.preventDefault();
return false;
}
});
我花了几个小时试图找到解决方案。如果有人可以提供帮助,将不胜感激!