Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#12097 closed bug (invalid)

crossDomain in IE9 is interpreted wrong

Reported by: [email protected] Owned by: [email protected]
Priority: undecided Milestone: None
Component: ajax Version: 1.7.2
Keywords: Cc: jaubourg
Blocked by: Blocking:

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 (11)

comment:1 Changed 11 years ago by dmethvin

Component: unfiledajax
Owner: set to [email protected]
Status: newpending

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 11 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 11 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 11 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 Changed 11 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 11 years ago by [email protected]

Status: pendingnew

"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 11 years ago by dmethvin

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

comment:8 Changed 11 years ago by jaubourg

Resolution: invalid
Status: newclosed

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 11 years ago by jaubourg (previous) (diff)

comment:10 in reply to:  9 Changed 11 years ago by [email protected]

*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 11 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). 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 :)

Version 0, edited 11 years ago by jaubourg (next)
Note: See TracTickets for help on using tickets.