2013-12-10 28 views
3

我發送POST reuqst到服務器獲取餅乾,響應有一個cookie,我需要存儲JQuery的 - 從響應

$.ajax({ 
     type: "POST", 
     url: url + "api/Login", 
     headers: { "Authorization": headerData }, 
     xhrFields: { 
      withCredentials: true 
     }, 
     crossDomain: true, 
     dataType: "text" 
    }).then(
    function (data, textStatus, jqXHR) { 
     // get the current default Breeze AJAX adapter 
     var ajaxAdapter = breeze.config.getAdapterInstance("ajax"); 

     var cookies = document.cookie ? document.cookie.split('; ') : []; 

     for (var i = 0, l = cookies.length; i < l; i++) { 
      console.log(cookies[i]); 
     } 
     console.log('Cookie'); 

     ajaxAdapter.defaultSettings = { 
      headers: { 
       // any headers that you want to specify. 
       "Cookie": jqXHR.getResponseHeader('Set-Cookie') 
      }, 
     }; 

,但我不能retireve cookie的,我可以用什麼樣的工具?

這是服務器響應

HTTP/1.1 200 OK 
Cache-Control: no-cache 
Pragma: no-cache 
Expires: -1 
Server: Microsoft-IIS/7.5 
Set-Cookie: session-token=227c268d-dae5-4c54-a05a-90f2401592d3; domain=172.18.25.168; path=/ 
X-AspNet-Version: 4.0.30319 
X-Powered-By: ASP.NET 
Date: Tue, 10 Dec 2013 20:47:07 GMT 
Content-Length: 0 
+1

是您在域名'172.18.25.168'上的頁面嗎? – charlietfl

+0

是的,它位於此ip –

回答

0

你爲什麼不只是附和你的服務器端文件/打印餅乾,然後使用(數據)治療呢?

+1

服務器是odata服務,我使用常規jquery帖子登錄並需要將cookie附加到breeze ajax適配器 –