私は元々 のために働いていた機能を持っています$(form).submit()
。$("#savebutton").click()
メイン ビューに既に form.sumbit() 関数があるため、動作するように変更する必要がありました。唯一の問題は、ボタンがクリックされ、状態が有効なときにフォームの送信が停止することです。古いコード
$(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();
}
}
現在のコード
$(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;
}
});