I’m trying to stay DRY and use respond_to as I move to AJAX in my apps,
but
I’m getting some mysterious behavior. Here’s a simple form I’m testing
with:
<%= form_remote_tag :url => {:action => ‘submit’} %>
<%= submit_tag ‘Go’ %>
<%= end_form_tag %>
When I submit the following HTTP request is sent:
POST /test/submit HTTP/1.1
Host: localhost:3000
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3)
Gecko/20060426 Firefox/1.5.0.3
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9
,text/plain;q=0.8,image/png,/;q=0.5
Notice that “text/javascript” appears nowhere in the Accept list!
Because of
this absence I would not expect respond_to to correctly catch the AJAX
submission, and it doesn’t. Instead HTML is triggered every time.
respond_to do |wants|
wants.js { render } # Never triggered
wants.html { redirect_to :action => ‘WHY?’ } # Always triggered
end
If I remove the “wants.html” line my RJS template performs the expected
dynamic actions, so I know that Javascript is enabled, but I’m at a
complete
loss as to why the Accept headers are not being set… can anyone point
out
what I am missing?
Don