ajax beforesubmit,jquery - Ajaxsubmit, chaining events on beforeSubmit - Stack Overflow

I am trying to trigger couple functions in beforeSubmit. First, I want to check whether the selected option is valid. Second, I want to use a modal window and have the user confirm the changes. Here is some of the code:

$().ready(function() {

$('#myForm').submit(function() {

var options = {

success: showResponse,

beforeSubmit: chkService,

dataType: "json",

url:'actCustomer.cfm?vw=saveSvc&acctNum=1'

};

$('#myForm').ajaxSubmit(options);

return false;

});

showResponse = function(responseText, statusText) {

alert('am i here? ' + responseText);

$.ajax({

type: "post",

url: "actCustomer.cfm?vw=save",

cache: false,

success: function(result) {

alert(result);

},

error: function(xmlHttpRequest, status, err) {

confirm('Error: '+err);

$('#errDiv').html(err);

}

});

}

chkService = function(arr, $form, options) {

formData = 'service='+$('#svc').val();

$.ajax({

type: "post",

url: "actCustomer.cfm?vw=chkStuff",

data: formData,

cache: false,

success: function(result) {

result = $.trim(result);

if (result == 'Invalid') {

$('#errDiv').html('Invalid Selection').addClass('req');

return false;

} else if (result == 'Valid') {

return confirmUpdates(arr, $form, options);

} else {

$('#errDiv').html(result);

return false;

}

},

error: function(xmlHttpRequest, status, err) {

confirm('Error: '+err);

$('#errDiv').html(err);

}

});

}

// should we continue with the updates?

confirmUpdates = function(arr, $form, options) {

var dispMsg = 'some information here about updates.';

$('#msg-header').html('Confirmation of Updates!');

$('#msg-content').html(dispMsg).css('color','black');

$('#msg-action').html('

$("#Msg").html('

ajax-loader.gifConfirming updates...
');

$('#basic-modal-content').modal({ minHeight:320, minWidth:455 });

$('#btnModSubmit').click(function(){

// continue with the updates.

alert('continue >>');

return true;

});

$('#btnModClose').click(function(){

/* $.modal.close();

$("#formMsg").hide();

$('#formSub').show(); */

window.location.reload();

});

}

});

service:

The problem I am having is that as soon as I cannot have

return confirmUpdates(arr, $form, options);

work properly. It does launch the modal window, but it doesn't wait for the btnModSubmit click. It submits the form and I see the am i here? warning.

If the ajax call to stuff.cfm in chkOptions is valid, now go do the confirmUpdates. If the user clicks on btnModSubmit then return true to execute showResponse. If user clicks on btnModClose, then return false and don't execute showResponse. I am stuck at this point.

Is there a way to fix this?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值