0
我在我的aspx頁面上使用jquery ajax方法來調用後臺代碼中的web方法。如果調用失敗,出於任何原因,我想捕獲錯誤並顯示一個有意義的消息給用戶。以下是我的jquery ajax方法代碼。在jquery ajax方法中發生問題捕獲錯誤
$.ajax(
{
type:"POST",
url:"Default.aspx/createitem",
data:JSON.stringify({question : question, answer : ans, url : url, category : cat, maincat : maincat, validfrom : validfrom, validuntil :validuntil}),
contentType:"application/json; charset=utf-8",
dataType:"json",
success:function(msg)
{
alert(msg.d);
//success code goes here
},
Error:function(xhr, status, error) {
// Boil the ASP.NET AJAX error down to JSON.
var err = eval("(" + xhr.responseText + ")");
// Display the specific error raised by the server (e.g. not a
// valid value for Int32, or attempted to divide by zero).
alert(err.Message);
}
});
但是像「缺少參數」什麼都不成功函數也不誤差函數的任何錯誤的情況下得到執行的,我不得不檢查firebug.Please響應可能有人告訴我,我在做什麼錯誤?
謝謝。
謝謝你這麼much.such一個愚蠢的錯誤.. – kranthi 2010-05-12 08:14:38
只是用於測試目的,我已經改變了的WebMethod(其犯規存在)在$名稱.ajax'url'參數,那麼它沒有執行錯誤/成功函數。請告訴我原因嗎? – kranthi 2010-05-12 08:20:15