2013-03-02 84 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