Forum: Ruby on Rails AJAX request not setting Accept header

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Don W. (Guest)
on 2006-05-09 08:41
(Received via mailing list)
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
<snip />

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
Bill W. (Guest)
on 2006-08-30 22:55
(Received via mailing list)
Hi Don (or anybody who can help! ;-) )

I'm having exactly the same problem.  Did you ever figure this out?  Has
anybody gotten respond_to to actually work?

Thanks,
Bill
  ----- Original Message -----
  From: Don Walker
  To: removed_email_address@domain.invalid
  Sent: Monday, May 08, 2006 11:40 PM
  Subject: [Rails] AJAX request not setting Accept header


  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
  <snip />

  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



------------------------------------------------------------------------------


  _______________________________________________
  Rails mailing list
  removed_email_address@domain.invalid
  http://lists.rubyonrails.org/mailman/listinfo/rails
This topic is locked and can not be replied to.