0

I am attempting to extract a cookie from an AJAX request to another server. I have some code running client side in a simple web app which you can see below.

I can verify that I receive a response from the server and my credentials are accepted. My question is: how do I extract the cookie from the response?

When I log the current value it returns null. I attempted to use the document.cookie attribute after looking around at other solutions online, but I don't think I'm doing this correctly.

function doLogin() {   
  $.ajax({
    url: "https://servername.com/appserver/j_spring_security_check",
    type: 'post',
    async: true,
    data: {
      j_username: "uname",
      j_password: "***********"
    }
  }).done(function(response) {
    console.log("cookie : "+document.cookie)
  });
};
Sledge
  • 1,245
  • 1
  • 23
  • 47

1 Answers1

1

I'm afraid in case of client-side code, browsers won't allow you to 'steal' cookies from other sites using ajax requests. Check out this thread.

Community
  • 1
  • 1
pzmarzly
  • 778
  • 15
  • 29