Skip to main content

Bug Tracker

Side navigation

#10124 closed bug (invalid)

Opened August 24, 2011 06:44AM UTC

Closed August 24, 2011 10:25AM UTC

Last modified August 24, 2011 11:18AM UTC

$.ajax doesn't work with JS as response on IE9

Reported by: andrey.turkin@gmail.com Owned by:
Priority: low Milestone: None
Component: ajax Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:
Description

Here is code fragment to illustrate the problem:

<a href="/js">click me</a>
<div id="results"></div>
<script>
  $(function() {
    $('a').click(function() {
      $.ajax({url: $('a').attr("href")});
      return false;
    });
  });
</script>

GET /js returns simple javascript like

$('#results').append("hi");

This works with Firefox and Chrome but doesn't work with IE9 (9.0.8112.16421 on Win7) - jQuery tries to read xhr.responseXML and IE throws an "Unspecified exception".

Attachments (0)
Change History (2)

Changed August 24, 2011 10:25AM UTC by addyosmani comment:1

component: unfiledajax
priority: undecidedlow
resolution: → invalid
status: newclosed

From the sounds of it, /js is outputting JavaScript which you wish to be loaded and executed when the user clicks on a link. In order to achieve this you need to pass a dataType parameter with a value of 'script' back to $.ajax (eg. dataType: "script"). Alternatively, use $.getScript() to achieve the same. http://api.jquery.com/jQuery.getScript/

Changed August 24, 2011 11:18AM UTC by andrey.turkin@gmail.com comment:2

From the sounds of it, /js is outputting JavaScript which you wish to be loaded and executed when the user clicks on a link.

Yes.

In order to achieve this you need to pass a dataType parameter with a value of 'script' back to $.ajax (eg. dataType: "script").

Two issues here:

1) according to documentation, dataType will be determined from response content-type unless specified explicitly. In this example /js sends back "text/javascript" content type so explicit dataType shouldn't be needed

2) dataType: "script" doesn't work as well as getScript (which does the same) - browser sends smaller set of Accept types which includes "text/javascript", server responds just like with unspecified dataType, everything else is just the same.

Exception happens at https://github.com/jquery/jquery/blob/1.6.2/src/ajax/xhr.js#L145 which, if I understood correctly, happens before $.ajax callback is executed.

So I think this is valid issue