# AJAX form refreshing page

**URL:** <https://www.ruby-forum.com/t/ajax-form-refreshing-page/136480>\
**Category:** Rails\
**Created:** [May 2, 2008, 3:12pm UTC](https://www.ruby-forum.com/t/ajax-form-refreshing-page/136480 "2008-05-02T15:12:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cumom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bc8723/32.png) [@cumom](https://www.ruby-forum.com/u/cumom)\
**Post date:** [May 2, 2008, 3:12pm UTC](https://www.ruby-forum.com/t/ajax-form-refreshing-page/136480/1 "2008-05-02T15:12:22Z")

</div>

I am trying to have a page submit a form and have the result update a  
div instead of reloading the page, but everything I try refreshes the  
page. I thought the :update part would prevent a page refresh, but  
perhaps I am leaving something out.  
Here is an example of something I have tried:

\<%= form\_remote\_tag :url =\> { :action =\> :enter },  
:update =\> “position#{box\_num}” %\>

\<%= submit\_tag %\>

def enter  
#…process fields  
render(:layout =\> false)  
end

It looks like I am using Prototype Version: ‘1.6.0.1’  
Any ideas?

---

<div class="post-metadata">

**Author:** ![cumom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bc8723/32.png) [@cumom](https://www.ruby-forum.com/u/cumom)\
**Post date:** [May 2, 2008, 3:14pm UTC](https://www.ruby-forum.com/t/ajax-form-refreshing-page/136480/2 "2008-05-02T15:14:11Z")

</div>

On 2 May 2008, at 14:02, cumom wrote:

> \<%= submit\_tag %\>

It’s proabably not relevant, but the preferred way to do this is now

\<% form\_remote\_tag :url =\> { :action =\> :enter }, :update =\>  
“position#{box\_num}” do %\>

\<%= submit\_tag %\>  
\<% end %\>

Does your page/layout include prototype?

Fred

---

<div class="post-metadata">

**Author:** ![cumom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bc8723/32.png) [@cumom](https://www.ruby-forum.com/u/cumom)\
**Post date:** [May 2, 2008, 3:17pm UTC](https://www.ruby-forum.com/t/ajax-form-refreshing-page/136480/3 "2008-05-02T15:17:41Z")

</div>

Oh by the way, if it helps, the form\_remote\_tag code produces the  
following:

I see the “return false” there in the javascript, which should at  
least prevent it from submitting the form in the ordinary manner.

---

<div class="post-metadata">

**Author:** ![cumom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bc8723/32.png) [@cumom](https://www.ruby-forum.com/u/cumom)\
**Post date:** [May 2, 2008, 3:26pm UTC](https://www.ruby-forum.com/t/ajax-form-refreshing-page/136480/4 "2008-05-02T15:26:30Z")

</div>

On May 2, 8:13 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> It’s proabably not relevant, but the preferred way to do this is now
> 
> \<% form\_remote\_tag :url =\> { :action =\> :enter }, :update =\>  
> “position#{box\_num}” do %\>
> 
> \<%= submit\_tag %\>  
> \<% end %\>

I tried something close to that at one point. The example I saw had  
dashes before the closing %\>'s and I think it had \<%='s for the  
opening tags. I have updated my code to the preferred way you  
describe, but it is still doing the same thing.

> Does your page/layout include prototype?

This shows up in the page.

And the file is there, so it should be getting it.

---

<div class="post-metadata">

**Author:** ![cumom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bc8723/32.png) [@cumom](https://www.ruby-forum.com/u/cumom)\
**Post date:** [May 2, 2008, 3:38pm UTC](https://www.ruby-forum.com/t/ajax-form-refreshing-page/136480/5 "2008-05-02T15:38:48Z")

</div>

On 2 May 2008, at 14:16, cumom wrote:

> name=“authenticity\_token” type=“hidden”  
> value=“021ac9218aede727f7ed79f0185047a005c7c593” /\>
> 
> I see the “return false” there in the javascript, which should at  
> least prevent it from submitting the form in the ordinary manner.  
> It probably means that the code before the return false is raising an  
> exception. Installing firebug or similar should help you out. This  
> would happen for example if there was no div with id position8

Fred

---

<div class="post-metadata">

**Author:** ![cumom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bc8723/32.png) [@cumom](https://www.ruby-forum.com/u/cumom)\
**Post date:** [May 2, 2008, 3:57pm UTC](https://www.ruby-forum.com/t/ajax-form-refreshing-page/136480/6 "2008-05-02T15:57:37Z")

</div>

I have heard about firebug, but have never used it. It looks like it  
would be useful, thanks. Here is what it said:

element.dispatchEvent is not a function  
[http://127.0.0.1:3000/javascripts/prototype.js?1207561014](http://127.0.0.1:3000/javascripts/prototype.js?1207561014)  
Line 3972  
fire([Document pedigree], “dom:loaded”, undefined)prototype.js (line  
3972)  
\_methodized()prototype.js (line 246)  
fireContentLoadedEvent()prototype.js (line 4006)  
[Break on this error] element.dispatchEvent(event);

I will try to step through it unless some has any ideas

On May 2, 8:37 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![cumom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bc8723/32.png) [@cumom](https://www.ruby-forum.com/u/cumom)\
**Post date:** [May 2, 2008, 4:05pm UTC](https://www.ruby-forum.com/t/ajax-form-refreshing-page/136480/7 "2008-05-02T16:05:14Z")

</div>

On 2 May 2008, at 14:56, cumom wrote:

> I have heard about firebug, but have never used it. It looks like it  
> would be useful, thanks. Here is what it said:

related to [http://www.ruby-forum.com/topic/137465](http://www.ruby-forum.com/topic/137465) ?

Fred

---

<div class="post-metadata">

**Author:** ![cumom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bc8723/32.png) [@cumom](https://www.ruby-forum.com/u/cumom)\
**Post date:** [May 2, 2008, 4:22pm UTC](https://www.ruby-forum.com/t/ajax-form-refreshing-page/136480/8 "2008-05-02T16:22:22Z")

</div>

I have heard about firebug, but have never used it. It looks like it  
would be useful, thanks. Here is what it said:

element.dispatchEvent is not a function  
[http://127.0.0.1:3000/javascripts/prototype.js?1207561014](http://127.0.0.1:3000/javascripts/prototype.js?1207561014)  
Line 3972  
fire([Document pedigree], “dom:loaded”, undefined)prototype.js (line  
3972)  
\_methodized()prototype.js (line 246)  
fireContentLoadedEvent()prototype.js (line 4006)  
[Break on this error] element.dispatchEvent(event);

I will try to step through it unless some has any ideas

On May 2, 8:37 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![cumom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bc8723/32.png) [@cumom](https://www.ruby-forum.com/u/cumom)\
**Post date:** [May 2, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/ajax-form-refreshing-page/136480/9 "2008-05-02T16:27:07Z")

</div>

I remember reading about jquery and prototype conflicting, but I  
thought, it’s working for me right now…

Thanks for the quick and efficient help.

On May 2, 9:04 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
