AJAX request not setting Accept header


#1

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


#2

Hi Don (or anybody who can help! :wink: )

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

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