# Problem with AJAX when using passenger

**URL:** <https://www.ruby-forum.com/t/problem-with-ajax-when-using-passenger/162875>\
**Category:** Rails\
**Created:** [March 14, 2009, 11:12pm UTC](https://www.ruby-forum.com/t/problem-with-ajax-when-using-passenger/162875 "2009-03-14T23:12:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkbeili](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tkbeili](https://www.ruby-forum.com/u/tkbeili)\
**Post date:** [March 14, 2009, 11:12pm UTC](https://www.ruby-forum.com/t/problem-with-ajax-when-using-passenger/162875/1 "2009-03-14T23:12:29Z")

</div>

Hello,

I just switched to using Passenger from using Apache/Mongrel cluster.

## I have an AJAX form:

\<% form\_remote\_tag :url =\> {:controller =\> “networks”, :action =\>  
‘search’},  
:update =\> ‘searchResults’,  
:loading =\> “Element.hide(‘goBtn’);  
Element.show(‘fts-loader’)”,  
:complete =\>  
"Element.show(‘goBtn’);Element.hide(‘fts-loader’); " do %\>

```
        <table border="0" bgcolor="#E5E5E5" cellpadding="0">
          <tr>
            <td><span

```

## class=“headerTextGreen”\>Search&nbsp; \<%= text\_field\_tag ‘search\_phrase’, ‘’, :size =\> ‘20’, :class=\>‘search-box’ %\> \<%= image\_submit\_tag ‘btnGo.gif’, :id =\> ‘goBtn’, :class =\> ‘btnSearch’ %\> \<%= image\_tag ‘searchWait.gif’, :id =\> ‘fts-loader1’, :style =\> ‘display:none’, :size =\> “15x14” %\> \<% end %\>

This form takes search string and then displays search results in div  
inside the page ,searchResults, and this was working fine with  
Apache/Mongrel.

After using Passenger it still works but instead of displaying search  
results in the “searchResults” div, it refreshes the whole page with the  
search results as the div is the only page that the page has.

Any ideas?

Thanks,

Tam

---

<div class="post-metadata">

**Author:** ![tkbeili](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tkbeili](https://www.ruby-forum.com/u/tkbeili)\
**Post date:** [March 15, 2009, 1:48am UTC](https://www.ruby-forum.com/t/problem-with-ajax-when-using-passenger/162875/2 "2009-03-15T01:48:41Z")

</div>

what’s in the source of generated page? c&p form code

Tam K. wrote:

> Element.show(‘fts-loader’)",  
> \<%= image\_submit\_tag ‘btnGo.gif’, :id =\> ‘goBtn’,  
> Apache/Mongrel.
> 
> After using Passenger it still works but instead of displaying search  
> results in the “searchResults” div, it refreshes the whole page with the  
> search results as the div is the only page that the page has.
> 
> Any ideas?
> 
> Thanks,
> 
> Tam

# –

Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

# [www.meinlschmidt.com](http://www.meinlschmidt.com) www.maxwellrender.cz www.lightgems.cz

---

<div class="post-metadata">

**Author:** ![tkbeili](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tkbeili](https://www.ruby-forum.com/u/tkbeili)\
**Post date:** [March 15, 2009, 2:34am UTC](https://www.ruby-forum.com/t/problem-with-ajax-when-using-passenger/162875/3 "2009-03-15T02:34:08Z")

</div>

Thanks Tom: Here is the Ruby code

* * *

def search  
@page = params[:page]  
@page ||= 1;  
@search\_phrase = params[:search\_phrase]  
@search\_phrase ||= ‘’

```
@users = User.search(@search_phrase,
          :sphinx => {:limit => $NUM_USER_SEARCH_RSLTS, :page => 

```

@page,:weights =\> [100,60,20,20]},  
:per\_page =\> $NUM\_USER\_SEARCH\_RSLTS, :page =\> @page)  
@userColleagues =  
User.find\_by\_id(session[:user\_id]).colleagues(:all, :conditions =\>  
[“networks.mutual = ?” , true])  
@is\_network\_owner = false  
@is\_network\_owner = true if params[:id].to\_i==session[:user\_id]

```
render :partial => 'user_search_results', :locals => {:users => 

```

@users, :@userColleagues =\> @userColleagues, :@is\_network\_owner =\>  
@is\_network\_owner}

## end

Thanks,  
Tam

---

<div class="post-metadata">

**Author:** ![tkbeili](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tkbeili](https://www.ruby-forum.com/u/tkbeili)\
**Post date:** [March 15, 2009, 4:22pm UTC](https://www.ruby-forum.com/t/problem-with-ajax-when-using-passenger/162875/4 "2009-03-15T16:22:45Z")

</div>

| Search | | ![Searchwait](https://www.ruby-forum.com/images/searchWait.gif?1237061985) |

Thanks Tom…

Cheers,  
Tam

---

<div class="post-metadata">

**Author:** ![tkbeili](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tkbeili](https://www.ruby-forum.com/u/tkbeili)\
**Post date:** [March 15, 2009, 9:36am UTC](https://www.ruby-forum.com/t/problem-with-ajax-when-using-passenger/162875/5 "2009-03-15T09:36:59Z")

</div>

Tam… I meant html source of generated page with the form…

tom

Tam K. wrote:

> ```
> :sphinx => {:limit => $NUM_USER_SEARCH_RSLTS, :page => 
> 
> ```
> 
> @is\_network\_owner}
> 
> ## end
> 
> Thanks,  
> Tam

# –

Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

# [www.meinlschmidt.com](http://www.meinlschmidt.com) www.maxwellrender.cz www.lightgems.cz

---

<div class="post-metadata">

**Author:** ![tkbeili](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tkbeili](https://www.ruby-forum.com/u/tkbeili)\
**Post date:** [March 15, 2009, 7:01pm UTC](https://www.ruby-forum.com/t/problem-with-ajax-when-using-passenger/162875/6 "2009-03-15T19:01:03Z")

</div>

try to add :method=\>:get into your form\_remote\_tag …

\<% form\_remote\_tag (  
:url =\> {:controller =\> “networks”, :action =\> ‘search’},  
:method =\> :get,  
:update =\> ‘searchResults’,  
:loading =\> “Element.hide(‘goBtn’); Element.show(‘fts-loader’)”,  
:complete =\> “Element.show(‘goBtn’);Element.hide(‘fts-loader’);”) do  
%\>

tom

Tam K. wrote:

> Search
> 
> Thanks Tom…
> 
> Cheers,  
> Tam

# –

Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

# [www.meinlschmidt.com](http://www.meinlschmidt.com) www.maxwellrender.cz www.lightgems.cz

---

<div class="post-metadata">

**Author:** ![tkbeili](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tkbeili](https://www.ruby-forum.com/u/tkbeili)\
**Post date:** [March 17, 2009, 5:18am UTC](https://www.ruby-forum.com/t/problem-with-ajax-when-using-passenger/162875/7 "2009-03-17T05:18:45Z")

</div>

Thanks Tom and Jermy. The problem was resolved by using the right  
version of Rails. The server version was 2.2.2 and my local computer  
version is 2.1.0. The code I posted worked fine after installing Rails  
2.1.0 gem on my server!  
I might try the solutions you provided if I use later verion of Rails,  
the code I write might be getting interpreted differently with Rails  
2.2.2.  
Cheers,  
Tam

---

<div class="post-metadata">

**Author:** ![tkbeili](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tkbeili](https://www.ruby-forum.com/u/tkbeili)\
**Post date:** [March 16, 2009, 10:14am UTC](https://www.ruby-forum.com/t/problem-with-ajax-when-using-passenger/162875/8 "2009-03-16T10:14:20Z")

</div>

Other than ensuring the routing (which seems to be connecting to some  
action or other), I recommend you also check the submit button you are  
using.

The form remote tag builds a form which has a javascript method called  
onsubmit() which is what submits the ajax form. If you use some type  
of custom submit button that one way or another calls form.submit (how  
non ajax forms are submitted) rather than onsubmit, then you will get  
what you are seeing now, with the javascript response shown as a page.
