2010-02-18 108 views

回答

11

ajax function has a beforeSend event,您可以使用提交表單前顯示對話框。

如果對話框指示不應該提交表單,那麼您將從函數返回false,以便不會發生表單提交。

在你的情況,你會做以下幾點:

$.ajax({ 
    beforeSend: function (request) { 
     // This is where you show the dialog. 
     // Return false if you don't want the form submitted. 
    }, 

    type: "POST", 
    url: "delete/process.php", 
    data: "delcustomerid="+ delcustomerid, 
    success: refreshTable 
}); 

如果您正在發行的形式POST(這好像你),我強烈建議你看一看的jQuery form plugin因爲它簡化了通過AJAX爲表單提交表單的過程,並且使用與ajax的調用相同的所有參數。

+0

我已經使用了jquery表單插件,但遇到了一些問題。我發現它更容易(不是更快的笑)做沒有插件的事情。感謝您的答案,這正是我正在尋找的。什麼是(請求)? – user272899 2010-02-18 18:51:31

+0

@ user272899:請求參數包含將用於發出請求的XMLHTTPRequest實例。你不一定需要它,但它傳遞給函數。 – casperOne 2010-02-18 19:34:28

+0

@ user272899:另外,如果你想要,詳細說明jQuery表單插件問題。我已經寫了一些關於在這裏使用jQuery表單插件和驗證(你必須查找的東西)的信息:http://stackoverflow.com/questions/1996125/how-to-use-jquery-validation-plugin-用的元數據和最jQuery的表單的插件-WI – casperOne 2010-02-18 19:35:29

1

您需要創建一個函數,使您在檢查用戶輸入後顯示的調用。

如:

function DeleteWithCheck() { 
    if (confirm("Are you sure you want to delete customer "+delcustomerid.ToString())) 
    { 
    $.ajax({ 
     type: "POST", 
     url: "delete/process.php", 
     data: "delcustomerid="+ delcustomerid, 
     success: refreshTable 
    }); 
    } 
    else 
    alert("Aborted"); 
} 

呼叫,當你想要做刪除此功能。