I have an API which you can access through web url. You can sign in by POSTing your username/password to let's say
http://myapi.example/signin
I do that with a jQUERY's $.post request which works fine - I get the status OK back if everything is correct. Now I need to somehow GET data from this API with certain url, which I would do with $.get of course, but I get the reponse unauthorized… So probably the session somehow gets lost, after the POST request/response.
I know that this POST/GET works, because if I do signin and then just type the GET url in browser - i get the response text plain in browser.
How would you keep the "session" somehow to simulate browser's behaviour in this?
function ajaxSignIn(){
$.post(url,
{
email: document.getElementById("name").value,
password: document.getElementById("password").value
},
function(data,status){ // this is where POST is successful (i get data in)
console.log("\nStatus of POST: " + status);
console.log(data);
$.get(urlForGet,function(data,status){ // GET call
console.log("Status of GET: " + status);
});
});
}
If I was unclear please ask for more info. Thank you for any help.