2012-04-25 81 views
0

我有一個ASP.Net MVC 3應用程序,使用一個jQuery .ajax的調用張貼到服務器側控制器動作如下ASP.Net MVC 3 JsonResult重定向錯誤

客戶端的jQuery呼叫:

//Page the server 
     $.ajax({ 
       url: '/Home/Call_Abort', 
       type: 'POST', 
       data: "{ 'op_id': '" + ajaxOPID + "', 'statMsg': '" + ajaxStatMsg + "'}", 
       contentType: 'application/json; charset=utf-8', 
       success: function (data) { 
         window.location.href = data.redirectUrl; 
       }, 
       error: function (xhr, ajaxOptions, thrownError) { 
         alert("Error while paging the server to abort. Reported error: '" + xhr.responseText + "'."); 
       } 
     }); 

服務器的控制器動作:

[HttpPost] 
public JsonResult Call_Abort(string op_id, string statMsg) 
{ 
    return Json(new 
    { 
     redirectUrl = Url.Action("Operator_Home", "Home", new { op_id = op_id, status = statMsg }), 
     isRedirect = true 
    }); 

} 

返回網址應該將用戶重定向到一個不同的視圖(即Operator_Home視圖)。這適用於我的本地開發PC,按預期路由到Operator_Home視圖,但是當我在我的開發Web服務器(Server 2008 with IIS 7)上運行它時,我得到以下404錯誤頁面,作爲xhr.responseText導致上面的.ajax調用。

enter image description here

好像發生了什麼事是不是重定向到我的的redirectUrl(即Operator_Home)指定View,它似乎認爲Call_Abort控制器動作應該返回一個Call_Abort查看,因爲沒有這樣的視圖存在下面的錯誤得到扔掉。但是,爲什麼會發生在Web服務器上,而不是運行Visual Studio開發服務器的本地PC?是否有一些設置需要在IIS上調整我的應用程序,以使其像我的開發計算機上那樣運行。我對MVC路由的理解還不夠清楚,不知道爲什麼會出現這種情況。任何幫助或洞察力,表示讚賞。

UPDATE

我的道歉,有幾個服務器,我有我的地方employemnt的,我引用了錯誤的Web服務器的工作。我上運行該服務器是服務器2008 IIS7

enter image description here

+0

我刪除了我的答案,因爲我絕對沒有解決它的根本問題。實際上,我沒有使用IIS6與MVC,所以我不能回答我認爲是根本原因。 – 2012-04-25 20:20:53

+0

謝謝安德魯,我確實犯了一個錯誤,在我的工作中我們有幾臺服務器,並且我引用了錯誤的服務器。特定的Web服務器是運行IIS 7的Server 2008. – kingrichard2005 2012-04-25 20:24:23

+0

如果您有應用程序錯誤斷點,您可以在附加到服務器後發佈實際錯誤嗎? – mirezus 2012-04-25 21:32:49

回答

0

錯誤竟然是在臨屋的URL的問題。阿賈克斯致電我修改了網址如下:

//Page the server 
var abortURL = window.location.origin + '/myApp/Home/Call_Abort'; 
     $.ajax({ 
       url: abortURL, 
       type: 'POST', 
       data: "{ 'op_id': '" + ajaxOPID + "', 'statMsg': '" + ajaxStatMsg + "'}", 
       contentType: 'application/json; charset=utf-8', 
       success: function (data) { 
         window.location.href = data.redirectUrl; 
       }, 
       error: function (xhr, ajaxOptions, thrownError) { 
         alert("Error while paging the server to abort. Reported error: '" + xhr.responseText + "'."); 
       } 
     }); 

這解決了這個問題,並允許jQuery完成POST。