Bug Tracker

Opened 6 years ago

Closed 6 years ago

#14404 closed bug (wontfix)

jQuery.ajax behaves differently when solve the sourceMappingURL

Reported by: jeffrey.zksun@… 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>

Change History (2)

comment:1 Changed 6 years ago by dmethvin

#14405 is a duplicate of this ticket.

comment:2 Changed 6 years ago by dmethvin

Resolution: wontfix
Status: newclosed

If you do not make a script request, jQuery must use an XMLHttpRequest to retrieve the text. Only after it receives the text does it also receive the Content-Type in the header to find out it is a script. At that point it evaluates the script with the context being the document which fetched the text, causing the issue you see.

If you want the sourcemap to work, use a "script" dataType.

Note: See TracTickets for help on using tickets.