Problem with AJAX when using passenger


#1

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 
<%= 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


#2

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 www.maxwellrender.cz www.lightgems.cz


#3

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


#4
Search Searchwait

Thanks Tom…

Cheers,
Tam


#5

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 www.maxwellrender.cz www.lightgems.cz


#6

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 www.maxwellrender.cz www.lightgems.cz


#7

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


#8

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.