任何人都可以告诉我为什么我的提交没有被执行?日志告诉我:"验证通过,将提交表格",但是没有提交?
$(function(){
$("#ajax-payment-form input[type='submit']").click(function(e) {
// Prevent form submission
e.preventDefault();
// Serialize data, make AJAX call
var str = $("#ajax-payment-form").serialize();
$.ajax({
type: "POST",
url: templateDir+"/payment_form/payment_process.php",
data: str,
context: this
}).done(function(msg) {
// If a response is received from your server
if(msg == 'OK') {
console.log('Validation passed, will submit form');
$(this).closest("form").submit();
} else {
console.log(msg);
}
}).fail(function() {
console.log('AJAX error');
});
});
});
感谢您的时间
塔尔
答案 0 :(得分:0)
这样做:
$(function(){
$("#ajax-payment-form input[type='submit']").click(function(e) {
// Prevent form submission
var $this = $(this);
e.preventDefault();
// Serialize data, make AJAX call
var str = $("#ajax-payment-form").serialize();
$.ajax({
type: "POST",
url: templateDir+"/payment_form/payment_process.php",
data: str,
context: this
}).done(function(msg) {
// If a response is received from your server
if(msg == 'OK') {
console.log('Validation passed, will submit form');
$this.closest("form").submit();
//....
答案 1 :(得分:0)
或更短的代码:(注意提交事件)
$(function(){
$("#ajax-payment-form").submit(function(e) {
e.preventDefault();
var $form = $(this);
$.post(
url: templateDir+"/payment_form/payment_process.php",
$form.serialize(),
function(){
if(msg == 'OK') {
console.log('Validation passed, will submit form');
$form.closest("form").submit();
} else {
console.log(msg);
}
},
'json'
).fail(function() {
alert( "error" );
});
});
});