5

I'm using jQuery's ajax .get method to retrieve data from my server. Works perfect in Chrome, but in IE9 it is not sending the Cookie header and that breaks the app. Any idea why? Here's the jQuery code:

$.get(this.server + 'rest/photo/' + this.profileId + '/count', function(data) {
    $('#imageCount').html(data);
});
at.
  • 50,922
  • 104
  • 292
  • 461

2 Answers2

1

I have the same problem here, I can't get the jQuery .ajax() function to work. The only workaround I found is this:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /> 

You can add this meta tag to the top of the page to get it working. But it doesn't feel like a good solution. I think the problem is that the xmlhttprequest object in IE9 is different, so jQuery cannot find the respective object, therefore ajax is not triggering.

DarthJDG
  • 16,511
  • 11
  • 49
  • 56
Alcatraz
  • 11
  • 1
0

I ran into a similar issue to the OP many years later with IE9 which, sadly, is still hanging on.

Every browser I tried, including IE10+, seemed fine with passing cookies to my backend, but IE9 would just drop them. It didn't seem to matter what attributes were on the cookies. The main page and API were on the same domains and the cookies matched, the schemes were the same. I wasn't doing anything with IFRAMES, so the P3P 'potato' hack didn't help.

So I started doing some research on what it was about IE9 that could be different. This Microsoft post was very enlightening, and outlines all the things the IE8 and IE9 did to help lock down CORS security holes:

  • Must use HTTP(S), and both endpoints must use the same scheme
  • Must use GET/POST
  • No custom headers allowed
  • Only text/plain content-type allowed
  • More sensitive to Security Zone settings
  • Cookies will be stripped from the request

That last item about the cookies got me thinking, what if IE9 thought I was making a cross-site request? It certainly looked like it was getting shot down in fine fashion like that. I had already checked some of the obvious things like the scheme and domain, but maybe I didn't check everything.

The solution? Specifically, I was using reqwest as my ajax library. It has a cross-origin parameter, which I had left set to true for some reason. Setting it (correctly) to false did the trick - all my cookies were picked up by the server. So it was a dumb mistake, but I learned a thing or two.

Hope this helps someone!

Community
  • 1
  • 1
killthrush
  • 4,859
  • 3
  • 35
  • 38