Bug Tracker

Ticket #12097 (closed bug: invalid)

Opened 2 years ago

Last modified 2 years ago

crossDomain in IE9 is interpreted wrong

Reported by: youcangetme@… Owned by: youcangetme@…
Priority: undecided Milestone: None
Component: ajax Version: 1.7.2
Keywords: Cc: jaubourg
Blocking: Blocked by:

Description

In jQuery 1.7.2 downloaded today I have to enter the crossDomain value as false in order to get it to do CORS. If FireFox the value only works when set to true.

My ugly workaround is below;

$.ajax({

url: this.dfcore.settings.server+'API/Login.jsp', type: 'POST', crossDomain: true == !(document.all), processData: false, data: lreq, success: function(data) {

console.log('Success: '+data);

}, error: function(jqXHR,err) {

console.log(jqXHR.status+": "+jqXHR.statusText);

}

});

Change History

comment:1 Changed 2 years ago by dmethvin

  • Owner set to youcangetme@…
  • Status changed from new to pending
  • Component changed from unfiled to ajax

This isn't enough information for a bug report. Is it actually a cross-domain request? IE9 doesn't support CORS. Can you reproduce in jsFiddle.net, perhaps less the cross-domain request, so we have some real code to use as a starting point for a repro?

comment:2 Changed 2 years ago by anonymous

"Is it actually a cross-domain request? IE9 doesn't support CORS."

Sorry to inform you but IE9 supports CORS. Maybe the reason you think it doesn't is because you have the values backwards in IE? Is this enough information now to consider this a valid bug report? Maybe instead of being a bug its simply a bad implementation?

comment:3 Changed 2 years ago by anonymous

Here you go, IE7 thru IE10 CORS using jQuery! Note that I have to reverse the "crossDomain" value inorder to get it to work, which is the bug or bad implementation I am reporting;

<!DOCTYPE html>
<html>
	<head>
		<title>jQuery CORS in IE7 - IE10</title>
		<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
		<script>
			$(document).ready(function() {
			  $.ajax({
			    url: "http://dreamfactorysql.cloudapp.net/API/index.php",
			    dataType: "text",
					async: true,
					type: 'GET',
					cache: false,
					crossDomain: true == !(document.all),
			    success: function(txt) {
			    	alert(txt);
			    }
			  });
			});
		</script>
		</head>
	<body>
		IE7 thru IE10 CORS Example Using jQuery
	</body>
</html>

comment:4 Changed 2 years ago by dmethvin

Okay you got me there. IE9 supports the CORS protocol via XDomainRequest, just not through a JavaScript API that matches the other browsers. I am assuming you've included that elsewhere?

Your code snippet threads its way through several  XDomainRequest limitations such as the inability to specify a content type other than text.

comment:5 follow-up: ↓ 6 Changed 2 years ago by dmethvin

  • Cc jaubourg added

You mentioned IE7 though, I don't think XDomainRequest works on IE7.

comment:6 in reply to: ↑ 5 Changed 2 years ago by youcangetme@…

  • Status changed from pending to new

"You mentioned IE7 though, I don't think XDomainRequest works on IE7."

Gotcha Again! Test the code on IE7, IE8, IE9 and IE10 ;-)

If I'm not mistaken, CORS is a Microsoft contribution, like Canvas was from Apple.

comment:7 Changed 2 years ago by dmethvin

Perhaps my copy/paste skills are lacking. Please provide a jsFiddle.

comment:8 Changed 2 years ago by jaubourg

  • Status changed from new to closed
  • Resolution set to invalid

 http://jsfiddle.net/44yue/3/

This is, of course, failing in IE9 with an Access Denied error.

That's the reason why we ask for jsFiddle test cases. You have something specific in your environment that enables cross-domain requests (I gather you load the page from the file system).

BTW, the IE9- XHR implementation doesn't support CORS or else  https://github.com/jquery/jquery/blob/master/src/ajax/xhr.js#L43 would be true.

You can get IE to accept cross-domain requests but it involves something we do not support: phone app environment, page accessed through the file system protocol (your case most probably), custom security settings, etc. As usual with unsupported environments, you have to use tricks.

Here, what you should do is this:

jQuery.support.cors = true;

Which is, of course, wrong but close enough for your specific use-case and should take care of all your needs.

Oh, BTW, gotcha.

Last edited 2 years ago by jaubourg (previous) (diff)

comment:9 follow-up: ↓ 10 Changed 2 years ago by jaubourg

comment:10 in reply to: ↑ 9 Changed 2 years ago by youcangetme@…

*sigh*

This is an existing app that is being ported to jQuery. It runs currently without any problems and yes, it does cross domain posts and gets. Yes, it doesn't run in other browsers though. I believe the app is 8 years old now? I see a lot of code from 2004 where this cross-domain implementation sits. I would have to check when the owner gets back from Airventure.

I guess what I will do is revert back to the old way since it works without any of these issues. I will simply do a manual "everybody else" branch in execution and role my own.

comment:11 Changed 2 years ago by jaubourg

If you set jQuery.support.cors to true, it should work flawlessly ((provided you limit yourself to text-only requests -- which you probably do since it worked before in plain javascript -- edited because I'm probably confusing with the XDR imp here)). I know it sucks but there is a limit to what jQuery can infer without assuming too much. That's why it's so awesome to work on end-products, you can assume so much more ;)

Best of luck for the port :)

Last edited 2 years ago by jaubourg (previous) (diff)
Note: See TracTickets for help on using tickets.