1
我想觸發beforeSubmit中的幾個函數。首先,我想檢查選定的選項是否有效。其次,我想使用模式窗口並讓用戶確認更改。下面是一些代碼:Ajaxsubmit,提前鏈接事件提交
<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>
我遇到的問題是,一旦我不能有 回報confirmUpdates(ARR,$形式,選項); 正常工作。它會啓動模式窗口,但不會等待btnModSubmit單擊。它提交的表格,我看到我在這裏?警告。
如果Ajax調用在chkOptions到stuff.cfm是有效的,現在轉做confirmUpdates。如果用戶點擊btnModSubmit,則返回true以執行showResponse。如果用戶點擊btnModClose,則返回false並且不執行showResponse。我被困在這一點上。
有沒有辦法解決這個問題?