No Session Cookies on Internet Explorer 9 AJAX req

2019-02-12 04:48发布

问题:

Internet Explorer 9 is not sending session cookies with my AJAX requests.

When I issue an authentication request to my API via AJAX, it returns a response that sets a session cookie. Subsequent calls to the API via AJAX do not send the cookie back to the server.

The API is located on the same host. Similarly, regular non-AJAX page requests also do not show the session cookie. I turned off all privacy and security settings in Internet Options. Chrome sends the cookies properly.

How do I get IE to return the cookies? Thanks!

回答1:

The URL I was attempting to access used an underscore character ('_'). This is an invalid URL and so Internet Explorer does not accept the cookies properly. Fixing this solved my instance of the problem.



回答2:

I had this issue with IE9 for a get request. I converted from $.getJSON (using a url with query string parameters) to $.ajax (using a post). My theory would be that similar to MS's MVC server library, IE doesn't like get requests that return JSON.(you have to specifically allow this in MVC or it gives you an error indicating that get requests that return JSON have some security risk error) Anyway, since this was one of my top google hits, I figured I'd post what worked for me.



回答3:

Just put Math.random() in url like,

$.ajax({
    type: "GET",
    url: "getRequestData.do?parameter=GetModelService&t="+Math.random(),
    data: "sub=ADD",
    cache: false,
    ................
    ...............


回答4:

try to avoid using localhost or 127.0.0.1 as part of your URL and see if it makes any difference.