2013-03-02 53 views
0

我一直堅持在這一段時間了。我這裏有Ajax請求:jQuery - ajax - 後 - json請求 - 沒有帖子正文在一些URL

$.ajax({ 
    url: UPDATE_USER_INFO_URL , 
    type: "POST", 
    dataType: "json", 
    contentType: "application/json", 
    data: JSON.stringify({user:'user'}), 
    success: function (data, textStatus) { 
     if(data["statusCode"] && data["statusCode"] == 1) { 
      _callback(1,data); 
     } 
     else { 
      _callback(0,data); 
     } 
    }, 
    error: function (jqXHR, textStatus){ 
     _callback(0, {}); 
    }   
}); 

如果我設置UPDATE_USER_INFO_URL到特定的URL,小提琴手顯示什麼在身上。如果我將UPDATE_USER_INFO_URL設置爲其他內容(即使是無效的URL),它確實會將{user:'user'}放入提琴手​​的正文中。

隨着原UPDATE_USER_INFO_URL:

POST http://10.35.50.26:8080/SelfServiceWs/user/session/upduserinfo HTTP/1.1 
Accept: application/json, text/javascript, ; q=0.01 
Content-Type: application/json 
X-Requested-With: XMLHttpRequest 
Referer: http://10.35.50.26:8080/SelfService/ 
Accept-Language: en-us 
Accept-Encoding: gzip, deflate 
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) 
Host: 10.35.50.26:8080 
Connection: Keep-Alive 
Pragma: no-cache 
Cookie: JSESSIONID=0BF9D9CCCE9030E60AB0BCE5F6562CD8 
Authorization: Negotiate TlRMTVNTUAABAAAAl4II4gAAAAAAAAAAAAAAAAAAAAAGAbAdAAAADw== 
Content-Length: 0 

恰克網址/ SelfServiceWs/ABCDEF

POST http://10.35.50.26:8080/SelfServiceWs/abcdef HTTP/1.1 
Accept: application/json, text/javascript; q=0.01 
Content-Type: application/json 
X-Requested-With: XMLHttpRequest 
Referer: http://10.35.50.26:8080/SelfService/ 
Accept-Language: en-us 
Accept-Encoding: gzip, deflate 
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) 
Host: 10.35.50.26:8080 
Content-Length: 15 
Connection: Keep-Alive 
Pragma: no-cache 
Cookie: JSESSIONID=9E79779805579A7964E03AAD76DF043B 

{"user":"user"} 

我有很多其他的Ajax調用,一切都按預期工作。

它一定是我失蹤的小事。

+0

爲什麼你需要使用JSON.stringify發送數據?你爲什麼不試試_data:{user:'user'} _? – juanchopx2 2013-03-02 04:01:34

回答

1

我想通了這一點。

我對url/user/ssoauth有個身份驗證servlet過濾器,意外地(對我來說),它向/ user路徑下的URL(包括/ user/session/upduserinfo)發出eveything調用以發送授權標頭。將過濾器移至/ user/auth/ssoauth stop客戶端以在調用user/session/upduserinfo時發送授權標頭並修復問題。

<filter-mapping> 
    <filter-name>SecurityFilter</filter-name> 
    <url-pattern>/user/ssoauth</url-pattern> 
</filter-mapping> 

導致每個客戶端調用URL後/ user發送授權標頭。

今天我學到了一些新東西!

+0

謝謝!我有同樣的問題,只有我的身份驗證服務/過濾器是一個服務於nginx身份驗證子請求的PHP腳本。 – user237419 2015-03-02 17:29:43

0

試試這個

data: JSON.stringify({'user':'user'}), 
+0

這裏沒有運氣。另外,'JSON.stringify({user:'user'})'可以處理不同的URL。我注意到兩個請求之間的差異,第一個請求發送授權頭。我想弄明白爲什麼它這樣做。 – cfreak 2013-03-02 17:09:37