Jquery, format.js and IE

I’m trying to use jQuery to write all my js unobtrusively, and running
into a bit of a problem when triggering the format.js block in IE6 (and
possibly IE7). It returns the JSON string no problem, but instead of
parsing it, IE6 asks to download the resource as a .js file.

So if my url is ‘/pictures/1.js’, IE6 will ask to save or run ‘1.js’

I did do some digging, and I understand that IE sets / on the Accept
header. I’m not sure if it has to do with that or not. It is triggering
the format I’m asking for. It’s just that IE6 won’t recognize it as a
typical javascript response.

Here’s some code. Also note that this is for an image upload, so it’s
not a real AJAX request, and I’m using the jQuery Form plugin to post to
an iframe.

The details of my ajax call:

var options = {
url: /pictures/1.js,
iframe: true,
beforeSubmit: prepImageArea,
success: imageUploaded,
dataType: ‘script’,
beforeSend: function(xhr) {xhr.setRequestHeader(“Accept”,
“text/javascript”)}
}

And my respond_to block:

respond_to do |format|
  format.html { redirect_to edit_picture_path(@picture) }
  format.js { render :json => @picture.to_json(:methods =>

[:public_filename, :large_thumb]) }
end

Any suggestions? Thanks.

On Fri, 2008-09-26 at 01:38 +0200, Bryan M. wrote:

I’m trying to use jQuery to write all my js unobtrusively, and running
into a bit of a problem when triggering the format.js block in IE6 (and
possibly IE7). It returns the JSON string no problem, but instead of
parsing it, IE6 asks to download the resource as a .js file.

So if my url is ‘/pictures/1.js’, IE6 will ask to save or run ‘1.js’

did you try relaying on the request type per se,
without the .js on the url?

did you try relaying on the request type per se,
without the .js on the url?

Taking the .js off the url just triggers the html response. I can append
the url with the query string /?format=js (as if i had written “link_to
resource_path(@resource), :format => js”) but I run into the same
problem. Instead of asking to download/run a file called “resource.js”
it just asks to download/run a file called “resource.”

This does make me thing it’s a header problem with IE, but I’m still
pretty confused about it.