My Rails app uses the jquery.post() method to send some data from a “clickable” map marker to a controller in my application as seen below.
While the form field functions as normal (i.e. posts to controller and redirects to view), the clickable map marker only POSTs to controller and does NOT redirect to the specified view:
The server responses for the posts look like this
//--> THIS IS THE JQUERY 'POST' FROM THE MAP CLICK EVENT. DOES NOT REFRESH THE VIEW
Started POST "/index" for 127.0.0.1 at 2011-11-26 09:22:20 -0500
Processing by SearchController#index as HTML
Parameters: {"search"=>"The Hilton Club New York"}
Rendered text template (0.0ms)
Completed 200 OK in 5ms (Views: 4.2ms | ActiveRecord: 0.0ms)
//--> THIS IS THE RAILS FORM POST. THIS REDIRECTS TO 'index.html.haml'
Started POST "/index" for 127.0.0.1 at 2011-11-26 09:24:50 -0500
Processing by SearchController#index as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"zjnYqbCB2iEob9g25310tYgZRRuF/WPTwplf92Rho0o=", "search"=>"Hilton Hotel, Avenue of the Americas, New York, NY", "commit"=>"GO"}
Rendered text template (0.0ms)
Completed 200 OK in 7ms (Views: 5.9ms | ActiveRecord: 0.0ms)
The Javascript looks like this
$.post("/index", {search: place.name},"data","html")
The Rails controller code looks like this
def index
respond_to do |format|
format.html {render :text => "You searched for : #{params[:search]}"}
end
end
Any ideas?

The third argument to “$.post()” is supposed to be a function, one that’s to be called when the HTTP request is finished. The library will pass the returned content to that function.
Without a function there, whatever the server returns is simply ignored; the library cannot have any idea what to do with it.
Even then, as @Esailija notes in a comment, if your server is issuing a redirect anyway it’s not a good fit for ajax in the first place.