Skip to main content

Bug Tracker

Side navigation

#14403 closed bug (notabug)

Opened September 30, 2013 12:56PM UTC

Closed September 30, 2013 08:06PM UTC

jQuery.ajax behaves differently when solve the sourceMappingURL

Reported by: jeffrey.zksun@gamil.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
Description

I use jQuery.ajax to load the javascript file cross domain. The script code are as below. There is only one difference between test1.html and test2.html. In test1.html, the dataType is set to be 'script', but not in test2.html. If the dataType is not specified, it will infers from the MIME type. For the test2.html, the inferred dataType is also 'script'.

In Test1.html, the chrome devTools tries to load source map from http://code.angularjs.org/1.2.0rc1/angular.min.js.map. But in Tet2.html, it tries to load the source map from http://local.host:8081/web/angular.min.js.map, which is incorrect. This is the defect.

In my test code, the only difference is specifying the dataType or inferring it. So it seems like a jQuery defect, which affect the solved path of the source mapping url. More details are post here: stackoverflow.com/questions/19079171/jquery-ajax-behaves-differently-when-solve-the-sourcemappingurl

Test1.html

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script>

$.ajax({

url: "http://code.angularjs.org/1.2.0rc1/angular.min.js",

type: "GET",

dataType: "script",

success: function(){

if(typeof angular !== undefined )console.log('evaluated');

else console.log('not evaluated');

},

error: function(){ console.log('failure')}

});

</script>

Test2.html

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script>

$.ajax({

url: "http://code.angularjs.org/1.2.0rc1/angular.min.js",

type: "GET",

success: function(){

if(typeof angular !== undefined )console.log('evaluated');

else console.log('not evaluated');

},

error: function(){ console.log('failure')}

});

</script>

Attachments (0)
Change History (1)

Changed September 30, 2013 08:06PM UTC by dmethvin comment:1

resolution: → notabug
status: newclosed

When you tell jQuery that you want a script, it can use a script tag. When you don't, it assumes the content can be anything and it must use cross-domain ajax requests. Then it finds out the content is a script and evaluates it, but at that point the "origin" of the code is different since it's a string inside the current page.