# Jquery, format.js and IE

**URL:** <https://www.ruby-forum.com/t/jquery-format-js-and-ie/149544>\
**Category:** Rails\
**Created:** [September 26, 2008, 1:38am UTC](https://www.ruby-forum.com/t/jquery-format-js-and-ie/149544 "2008-09-26T01:38:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bryan82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@bryan82](https://www.ruby-forum.com/u/bryan82)\
**Post date:** [September 26, 2008, 1:38am UTC](https://www.ruby-forum.com/t/jquery-format-js-and-ie/149544/1 "2008-09-26T01:38:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bryan82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@bryan82](https://www.ruby-forum.com/u/bryan82)\
**Post date:** [September 26, 2008, 4:44am UTC](https://www.ruby-forum.com/t/jquery-format-js-and-ie/149544/2 "2008-09-26T04:44:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bryan82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@bryan82](https://www.ruby-forum.com/u/bryan82)\
**Post date:** [September 27, 2008, 5:10am UTC](https://www.ruby-forum.com/t/jquery-format-js-and-ie/149544/3 "2008-09-27T05:10:51Z")

</div>

> 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.
