Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  92] [ 5]  / answers: 1 / hits: 64036  / 9 Years ago, mon, april 27, 2015, 12:00:00

I have a simple jQuery AJAX POST code:



$.ajax({
type: POST,
url: AppConstants.URLs.PROXY,
data: message,
xhrFields: {
withCredentials: true
},
success: function(data, status, xhr) {
console.log(Cookie: + xhr.getResponseHeader(Set-Cookie));
}
});


and I wish to get the cookie and save it using cookies-js.



But according to http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders%28%29-method:





  1. Return all response headers, excluding headers that are a case-insensitive match for Set-Cookie or Set-Cookie2, as a single string, with each header line separated by a U+000D CR U+000A LF pair, excluding the status line, and with each header name and header value separated by a U+003A COLON U+0020 SPACE pair.




Using the Network tool in Chrome, Set-Cookie is visible in the Response headers. I also verified that the Set-Cookie header appears using curl.



What do I have to do to save the cookie in my front end app? Also, my app is running on https only.



I'd gladly provide more details upon request.


More From » ajax

 Answers
6

You can't get the cookie data in your JS. The API won't allow you.




What do I have to do to save the cookie in my front end app?




Just set the Set-Cookie header in the response from the server side code. The browser should save it automatically.



As a developer, you may be able to inspect the value of the cookies using Developer Tools.



And the same cookie will be sent in subsequent requests to the same domain, until the cookie expires.


[#66869] Saturday, April 25, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marint

Total Points: 550
Total Questions: 105
Total Answers: 124

Location: Zambia
Member since Sat, Oct 31, 2020
4 Years ago
;