2013-10-22 24 views
0

我有一個MVC4項目,在Visual Studio 2010中運行良好,但是當我將它部署到IIS時,我得到textstatus的「parsererror」和errorThrown的「syntaxError」(它以ajax錯誤方式登陸)。任何想法爲什麼?我正在使用IE8(在瀏覽器模式IE8和文檔模式IE8標準),但我已經包括json3.js剛剛incase ..我已經添加$ .support.cors = true,甚至嘗試過crossDomain = true,但似乎沒有得到它在IIS中工作,有什麼建議嗎?這裏是代碼:AJAX JSON請求到MVC IIS語法錯誤

JSON_AjaxRequest: function (controller, method, parameters, callBackSuccess) { 

    parameters = JSON.stringify(parameters); 

    var hasError = false; 
    var lastErrorMessage = ""; 

    $.support.cors = true; 

    $.ajax({ 

     type: "POST", 
     contentType: "application/json; charset=utf-8", 
     url: "http://myServer/myApplication/" + controller + "/" + method, 
     data: parameters, 
     success: function (data, textStatus, jqXHR) { 
      callBackSuccess(data); 
     }, 
     error: function (jqXHR, textStatus, errorThrown) { 
      hasError = true; 
      lastErrorMessage = errorThrown; 
     }, 
     complete: function (jqXHR, textStatus) { 

      if (hasError) { 
       var errorObject = MyBuildErrorMsgRoutine(lastErrorMessage); 
       MyDisplayErrorMsgRoutine(errorObject); 
      } 
     }, 
     dataType: 'json' 
}); 
+0

如果您檢查了對象'jqXHR',您會收到有關該問題的更多詳細信息。你提到你的問題,但你真的使用跨域請求? –

+1

爲什麼你使用跨域請求?使用像「」/「+ controller +」/「+ method」這樣的URL會不會更容易? – ITFarmer

+0

@Claudio在這種情況下沒有報告的問題,在jqXHR – Chris

回答

0

解決感謝ITFarmer讓我走上正軌。

對於內部VS2010使用:

url: "http://localhost:<port>/" + controller + "/" + method, 

對於IIS使用:

url: "/SiteName/ControllerName/MethodName" 

編輯:注意 '網站名稱' 我在這裏提到,實際上是在IIS應用程序的名稱,所以在看您看到網站的IIS樹,然後在「默認」(或其他)下,然後在那下面是您的應用程序名稱列表,我在上面稱之爲SiteName。