Jquery Ajaxsubmit,在beforeSubmit上链接事件

Jquery Ajaxsubmit,在beforeSubmit上链接事件,jquery,Jquery,我试图在beforeSubmit中触发两个函数。首先,我想检查所选选项是否有效。其次,我想使用一个模式窗口,让用户确认更改。下面是一些代码: <script type="text/javascript" language="javascript" src="scripts/jquery-latest.js"></script> <script type="text/javascript" language="javascript" src="scripts/jq

我试图在beforeSubmit中触发两个函数。首先,我想检查所选选项是否有效。其次,我想使用一个模式窗口,让用户确认更改。下面是一些代码:

 <script type="text/javascript" language="javascript" src="scripts/jquery-latest.js"></script>
 <script type="text/javascript" language="javascript" src="scripts/jquery.form.js" ></script>
 <script type="text/javascript" language="javascript" src="scripts/jquery.simplemodal-1.4.3.js"></script>
 <link rel="stylesheet" type="text/css" href="css/modalWins.css" />
 <script>
$().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('<div align="center" style="margin-top:30px;"><input type="button" name="btnModSubmit" id="btnModSubmit" class="button submit" value="Continue"/><input type="button" name="btnModClose" id="btnModClose" class="button close" value="Cancel" style="margin-left:30px"/></div>');
    $("#Msg").html('<table style="font-size:11px; color:#333; margin-left:35px;"><tr><td><img border="0" src="images/ajax-loader.gif"/></td><td style="font-weight:bold">Confirming updates...</td></table>');

    $('#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();
    });
}
 });
 </script>
  <form name="myForm" id="myForm" action="" method="post">
service:<input type="text" name="svc" id="svc" value="1">
    <input type="submit" name="submit" id="submit" class="button submit" value="Proceed"/>
 </form>

$().ready(函数()){
$('#myForm').submit(函数(){
变量选项={
成功:showResponse,
提交前:chkService,
数据类型:“json”,
url:'actCustomer.cfm?vw=saveSvc&acctNum=1'
};
$('#myForm')。ajaxSubmit(选项);
返回false;
});
showResponse=函数(responseText、statusText){
警报(‘我在这里吗?’+responseText);
$.ajax({
类型:“post”,
url:“actCustomer.cfm?vw=save”,
cache:false,
成功:功能(结果){
警报(结果);
},
错误:函数(xmlHttpRequest、状态、错误){
确认('错误:'+错误);
$('#errDiv').html(err);
}
}); 
}
chkService=函数(arr$form,options){
formData='service='+$('#svc').val();
$.ajax({
类型:“post”,
url:“actCustomer.cfm?vw=chkStuff”,
数据:formData,
cache:false,
成功:功能(结果){
结果=$.trim(结果);
如果(结果=‘无效’){
$('#errDiv').html('Invalid Selection').addClass('req');
返回false;
}else if(结果=‘有效’){
返回确认更新(arr$表格、选项);
}否则{
$('#errDiv').html(结果);
返回false;
}
},
错误:函数(xmlHttpRequest、状态、错误){
确认('错误:'+错误);
$('#errDiv').html(err);
}
}); 
}
//我们应该继续更新吗?
confirmUpdates=函数(arr,$form,options){
var dispMsg='此处有一些关于更新的信息';
$('#msg header').html('更新确认!');
$('#msg content').html(dispMsg.css('color','black');
$('#msg action').html('');
$(“#Msg”).html('确认更新…');
$(“#基本模式内容”).model({minHeight:320,minWidth:455});
$('#btnModSubmit')。单击(函数(){
//继续更新。
警报(“继续>>”);
返回true;
});
$('#btnModClose')。单击(函数(){
/*$.modal.close();
$(“#formMsg”).hide();
$('#formSub').show()*/
window.location.reload();
});
}
});
服务:
我遇到的问题是一旦我不能 返回确认更新(arr$表格、选项); 工作正常。它确实会启动模式窗口,但不会等待btnModSubmit单击。它提交了表格,我看到了我在这里吗?警告

如果chkOptions中对stuff.cfm的ajax调用有效,现在就执行confirmUpdates。如果用户单击btnModSubmit,则返回true以执行showResponse。如果用户单击btnModClose,则返回false,不执行showResponse。我被困在这一点上


有办法解决这个问题吗?

我结束了从ajaxSubmit删除成功的过程,如下所示

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

    var options = { 
        beforeSubmit: function(arr, $form, options) { 
            chkService(arr, $form, options);
            confirmUpdates(arr, $form, options);
            return false;
        },
        dataType: "json",
        url:'actCustomer.cfm?vw=saveSvc&acctNum=1'
        };
    $('#myForm').ajaxSubmit(options);
    return false;   
}); 
chkService首先运行。然后,它转到confirmUpdates。在那里,我有一个提交和取消按钮。如果他们单击“提交”,则我会将他们发送到另一个函数以保存表单:

  saveForm(arr, $form, options);
希望这对某人有帮助。 谢谢