2016-02-24 38 views
0

早安所有,Ext JS的Form.Submit總是返回失敗

我想一個很基本的form.submit,由於某種原因它總是回來爲失敗。 也在.NET中使用本地webservice。

我必須錯過一些非常基本的東西......或者可能是數據回來的方式。

我附上幾張照片,以顯示如何,我嘗試:

圖像1 - form.submit

enter image description here

圖像2 - service.cs

enter image description here

圖像3 - 我如何從本地返回.NET web服務的結果 enter image description here

道歉的圖像...由於某些原因剪切和粘貼代碼無法正常工作。

謝謝! 斯蒂芬

這裏是調試器的web服務中第一 行畫面被VAR可變 第二行(X2)被轉換使用JsonConvert.SerializeObject enter image description here

最後是從瀏覽器在返回的調試器的一個圖片到JSON enter image description here

我也一直在試圖理解CORS ...所以我增加了以下到我的web.config這不利於

<system.webServer> 
    <httpProtocol> 
     <customHeaders> 
     <add name="Access-Control-Allow-Origin" value="*"/> 
     <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" /> 
     <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" /> 
     </customHeaders> 
    </httpProtocol> 
    </system.webServer> 

進入這裏

這裏的代碼是Firefox的調試器 enter image description here

我調整我的web.config允許選項,仍然可以得到錯誤 狀態碼405不允許的方法

<system.webServer> 
    <httpProtocol> 
     <customHeaders> 
     <add name="Access-Control-Allow-Origin" value="*"/> 
     <add name="Access-Control-Allow-Headers" value="Content-Type" /> 
     <add name="Access-Control-Allow-Methods" value="OPTIONS, TRACE, GET, HEAD, POST, PUT" /> 
     <!--<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" /> 
     <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />--> 
     </customHeaders> 
    </httpProtocol> 
    </system.webServer> 

OKAY。 ..我做了一些改變...我從我的web.config中刪除了這些行,並添加了一個Global.asax.cs頁面,內容如下:

protected void Application_BeginRequest(object sender, EventArgs e) 
{ 
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); 
    if (HttpContext.Current.Request.HttpMethod == "OPTIONS") 
    { 
     HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache"); 
     HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST"); 
     HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, Authorization, X-Requested-With"); 
     HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000"); 
     HttpContext.Current.Response.End(); 
    } 
} 

現在看來成功了,但仍然失敗。我在這裏做些什麼?它是我的json格式嗎?

結果

newresult

json

network

+0

奇怪,一切看起來都正確。你能確保迴應是{success:true}?你正在使用什麼版本的extjs? – LightNight

+0

我回來顯示結果後,從我的web服務器和瀏覽器添加了調試器視圖。也我相信我在版本6,但不知道如何檢查 – solarissf

+0

在控制檯檢查Ext.getVersion() – LightNight

回答

2

您的回覆有反斜槓,這不是有效的JSON。它必須是{"success":true},沒有反斜槓。

這應該是由於雙重序列化。在你調試它的地方,沒關係。但是你應該在別的地方再次序列化它。確保避免雙重序列化。

+0

其版本6.0250。我試着返回「{success = True}」的var json.ToString(),但這看起來不正確。如果我將瀏覽器更改爲Chrome,則我的預檢響應中有無效的http狀態代碼405 – solarissf

+0

終於找到了。感謝您的幫助,讓我通過它!它是返回一個糟糕的JSON格式的組合,它應該直接返回對象,而不是字符串版本。然後添加一個global.asax文件並在application_beginrequest中編輯httpcontext頭文件 – solarissf

相關問題