0
我有一個原本爲$(form).submit()
工作的功能。我不得不修改它在$("#savebutton").click()
上工作,因爲主視圖中已經有一個form.sumbit()函數。唯一的問題是當按鈕被點擊並且狀態有效時,表單停止提交。 舊代碼Jquery無法正常工作
$(document).ready(function() {
$("form").submit(function (e) {
e.preventDefault(); //prevent default form submit
$.ajax({
url: '@Url.Action("HasJobInProgress", "ClientChoices")/',
data: { id: '@Model.ClientId' },
success: function (data) {
showMsg(data);
},
cache: false
});
});
});
function showMsg(hasCurrentJob) {
if (hasCurrentJob == "True") {
alert("The current clients has a job in progress. No changes can be saved until current job completes");
return false;
} else {
$("form").unbind('submit').submit();
}
}
CurrentCode
$(document).ready(function() {
$("#saveButton").click(function (e) {
e.preventDefault(); //prevent default form submit
$.ajax({
url: '@Url.Action("HasJobInProgress", "Shared")/',
data: { id: '@Model.ClientId' },
success: function (data) {
showMsg(data);
},
cache: false
});
});
function showMsg(hasCurrentJob) {
if (hasCurrentJob == "True") {
alert("The current clients has a job in progress. No changes can be saved until current job completes");
return false;
} else {
$("form").submit();
}
return true;
}
});
更新(仍然沒有工作)
$(document).ready(function() {
$("#saveButton").click(function (e) {
if ($(e.currentTarget).data('shouldSubmit')) return;
e.preventDefault(); //prevent default form submit
$.ajax({
url: '@Url.Action("HasJobInProgress", "Shared")/',
data: { id: '@Model.ClientId' },
success: function (data) {
showMsg(data, e);
},
cache: false
});
});
function showMsg(hasCurrentJob, e) {
if (hasCurrentJob == "True") {
alert("The current clients has a job in progress. No changes can be saved until current job completes");
return false;
} else {
$(e.currentTarget).data('shouldSubmit', true);
$("#saveButton").click();
$(e.currentTarget).data('shouldSubmit', null);
}
return true;
}
});
我正在努力追蹤,但確實做出了嘗試。將張貼在上面。請讓我知道,如果你看到任何東西。 – 2012-04-12 16:25:09
@atbyrd,我沒有看到你的更新版本有什麼明顯的錯誤。我建議你嘗試用調試器來完成它。 – Joe 2012-04-12 17:01:58