To better illustrate my problem , the question could be:
Can I initiate a session from a JSONP request?
In more detail: Suppose a JSONP request is made from my browser to myserver.com. Can myserver.com set cookies through the JSONP response, so that later on, when requests are again made to myserver.com (either directly when doc.host = myserver.com or indirectly through another JSONP request from an arbitrary doc.host) those cookies will be sent to it? Currently the browser seems to ignore the cookies I send with JSONP responses. Is what I want possible? What am I missing here?
EDIT: This is the request I do , by loading a local js file through a dummy local html that just fetches latest jquery and loads the js file:
$.ajax({
url: "http://my-remote-server/jsonp/service/test",
dataType: 'jsonp',
data: {some:'data'},
success: function(responseData)
{console.log(responseData);}
});
The response of the above JSONP request, is setting a cookie. This is confirmed since chrome reports it. Problem is that if I just re-execute the above a second time, the cookie previously set isnt sent back to the server .
EDIT 2: I went to Chrome cookie browser (in the under-the-hood page) and I cant find the cookie, although it is reported (debug console of chrome) as received in the JSONP response. Which means that server sends it, browser sees it and then throws it away.
I found the solution, and here is some info that might be interesting for anyone dealing with this problem:
From wikipedia definition:
Third-party cookies are cookies being set with different domains from the one shown on the address bar
If I am not wrong, this makes 99.99% of all JSONP set cookies, third-party cookies. And in my case the address shown on the address bar is a file:// ,which makes my cookie a third party one.
As soon as I enabled third party cookies it worked.
As a side note, Chrome by default does not support cookies on file:// pages and doean not warn or notifies this. It has created some headaches .See here and here for the details.