# Ajax fails in IE8

**URL:** <https://www.ruby-forum.com/t/ajax-fails-in-ie8/189653>\
**Category:** Rails\
**Created:** [June 4, 2010, 2:59pm UTC](https://www.ruby-forum.com/t/ajax-fails-in-ie8/189653 "2010-06-04T14:59:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [June 4, 2010, 2:59pm UTC](https://www.ruby-forum.com/t/ajax-fails-in-ie8/189653/1 "2010-06-04T14:59:57Z")

</div>

hi guys,

I am testing a new optional funtionality in my site with IE 8 after  
success with Firefox 3.6.3, chrome and safari.

The new functionality basically sees a “sub category” drop down list  
get generated in my form as soon as a “Category” value is selected  
from the “Category” drop down list.

I have been using the standard rails api such as observe\_field, and  
collective\_select.

Anyway, when I loaded up the webpage on IE8 and selected a value from  
the “Category” drop down list, the form fails to show the subcategory  
drop down list.

Ajax doesn’t seem to be working here in IE8.  
I know that rails uses prototype.  
I have read that prototype 1.6RC2 is fully compatible with IE 8  
([http://www.prototypejs.org/2009/3/27/prototype-1-6-1-rc2-ie8-](http://www.prototypejs.org/2009/3/27/prototype-1-6-1-rc2-ie8-)  
compatibility-element-storage-and-bug-fixes) .  
I downloaded it and reloaded the webpage . No difference.

1. has anyone managed to get around the problem whereby ajax use in  
IE8 fails?
2. has anyone got an alternative such as using observe\_field/  
observe\_form and calling the whole url (appended with the selected  
values at the time to load the other dynamic values (in this case,  
category id which is appended to the url which would then load the  
whole page with a bunch of sub category values ) )?

thanks

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [June 4, 2010, 5:28pm UTC](https://www.ruby-forum.com/t/ajax-fails-in-ie8/189653/2 "2010-06-04T17:28:40Z")

</div>

On 4 June 2010 13:58, ct9a [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> collective\_select.
> 
> Anyway, when I loaded up the webpage on IE8 and selected a value from  
> the “Category” drop down list, the form fails to show the subcategory  
> drop down list.
> 
> Ajax doesn’t seem to be working here in IE8.

Just a thought, have you checked that your html is valid by pasting  
the complete page source into the w3c html validator? Differences  
between browsers is often down to invalid html.

Colin

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [June 5, 2010, 2:21am UTC](https://www.ruby-forum.com/t/ajax-fails-in-ie8/189653/3 "2010-06-05T02:21:25Z")

</div>

Hi, Colin,

Every page I make has to pass by W3C’s validation.

It’s a pity why IE8 doesn’t really support prototype and rails’ JS  
helpers are made out of prototype…

Any more ideas guys?

Gordon

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [June 5, 2010, 11:41am UTC](https://www.ruby-forum.com/t/ajax-fails-in-ie8/189653/4 "2010-06-05T11:41:00Z")

</div>

Hi,

As I have to guess your code, I can just share my experience with Ajax  
and IE.

I recently had a similar problem with the Ajax :update=\>’\<#id\>’ call.  
I updated a

element which went perfect in Firefox, but not in IE.  
After changing the

element into a

 my code fired in IE as  
well. So, you might check the HTML you’re using.

Jan

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [June 5, 2010, 11:49am UTC](https://www.ruby-forum.com/t/ajax-fails-in-ie8/189653/5 "2010-06-05T11:49:47Z")

</div>

ok i will look into it soon and report back. Thank you!

Anyone else? I m sure you guys use Ajax in your rails apps.

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [June 6, 2010, 3:15am UTC](https://www.ruby-forum.com/t/ajax-fails-in-ie8/189653/6 "2010-06-06T03:15:10Z")

</div>

hi there, Javinto,

I checked and my code swapped some

for

. Tested and still no  
good  
with IE8.

diff --git a/app/views/parts/\_form.html.erb  
b/app/views/parts/\_form.html.erb  
index c5cd780…eae7407 100644  
— a/app/views/parts/\_form.html.erb  
+++ b/app/views/parts/\_form.html.erb  
@@ -16,13 +16,13 @@  
\<%= render :partial =\> ‘sub\_categories/select’, :locals =\> {  
:part =\>  
@part } %\>

- 

- 
 \<%= observe\_field :part\_category\_id, :url =\> { :action =\> :get\_subcategories }, :update =\> :subcategory\_div, :with =\> 'category' %\>
  - 

  - 

\<%= image\_tag('required\_attribute.gif', :alt =\> "image for required

attribute") %\>  
diff --git a/app/views/parts/get\_subcategories.erb  
b/app/views/parts/get\_subcategories.erb  
index 9737bad…498001d 100644  
— a/app/views/parts/get\_subcategories.erb  
+++ b/app/views/parts/get\_subcategories.erb  
\<% if (!@sub\_categories.nil? and @sub\_categories.length \> 0) %\>  
-

+

  
Sub category:  
  
\<%= collection\_select(  
:part,  
{:include\_blank =\> true}  
)  
%\>  
-  
+
  
\<% end %\>

Any ideas?

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [June 6, 2010, 5:00am UTC](https://www.ruby-forum.com/t/ajax-fails-in-ie8/189653/7 "2010-06-06T05:00:30Z")

</div>

hi, guys,

I solved the problem.

SOLUTION: Do not explicitly include references to the prototype js  
framework.

# WHAT I HAVE IN MY SOURCE CODE (ie. “app/views/layouts/application.html.erb”):

> —Extract end

# WHY THE PROBLEM OCCURED IN MY SOURCE CODE:

1. Reading  
[http://www.51773.com/tools/api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html](http://www.51773.com/tools/api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html),  
rails includes the Rails includes the Prototype JavaScript  
framework. I  
suppose this is done by doing either the following in the head of the  
application ( in my case, “app/views/layouts/application.html.erb”).  
Here’s  
an extract from the link I pasted:

> libraries instead of fetching all the functions anew on every request."

1. I seemed to have repeatedly referenced prototype.js (ie via  
:defaults,  
and script=“javascript/text” )

# HOW I FIXED IT:

- Removed all references to prototype.js and left the :default call in  
the  
javascript include tag (ie. " \<%= javascript\_include\_tag :defaults,  
‘jquery’ %\>"
- Restarted the web server and tested changes on firefox 3.6.3, chrome,  
safari, IE 7 and IE 8 - worked as expected.

Hope this helps some of you using IE 8.

Gordon Y.
