現在我的ajax帖子都會觸發錯誤事件,即使該操作沒有導致錯誤。我有一個ASP.NET MVC的動作,看起來像:如何從ASP.NET MVC動作返回以允許jQuery ajax成功事件觸發?
[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult StuffToDo(int id)
{
// do various things that work ...
return new JsonResult(); // i have to return something, so this...
}
在客戶端我有這樣的jQuery:
$('#actionClick').click(function() {
if (confirm('Are you sure?')) {
$.ajax({
type: "POST",
url: "/Customer/StuffToDo/<%= Model.Customer.Id %>",
contentType: "application/json; charset=utf-8",
data: "{}",
dataType: "json",
success: function() {
ShowSuccessResult("Yay!");
},
error: function(xhr, ajaxOptions, thrownError) {
ShowErrorResult("Boo! Message:" + xhr.responseText);
}
});
}
return false;
});
如果操作成功(沒有拋出異常),那麼我會期待成功事件處理程序被觸發。相反,錯誤事件正在發射。有什麼我應該回傳或改變的行動,所以成功事件觸發?
我意識到這個問題基本上和this other question一樣,但是我的錯誤處理程序已經有了解決其他人問題的擴展簽名。
編輯 每要求,這裏是我得到的迴應:
Link to the screen shot(不知道如何表現出來的問題)
編輯 我改變了將值返回Null以查看是否影響任何內容,但不影響行爲。
編輯 它開始看起來像這與HTTPS的問題。我從請求中獲得多個回覆。前兩個是401消息,然後我得到一個200.
什麼是在HTTP響應? – Pointy 2010-02-05 16:37:49
可以發佈控制檯 – Cherian 2010-02-05 16:41:06
的firebug請求響應的屏幕截圖xhr.responseText是什麼? – 2010-02-05 16:42:44