How are XHR requests made when also a post?

11 views
Skip to first unread message

S Ahmed

unread,
Aug 15, 2017, 10:34:41 PM8/15/17
to rubyonra...@googlegroups.com
In rails 2.2 there was checks in the code like:

    ...
    if request.xhr?
    end
    ...

end


If a HTTP POST is made, how would also be considered a XHR request?



Thanks!

Norbert Melzer

unread,
Aug 16, 2017, 7:46:15 AM8/16/17
to rubyonra...@googlegroups.com
(new XMLHttpRequest).open('POST', 'foo.xml', 'data') via JavaScript should do a POST request. At least according to wikipedia. But Rails 2.2 is quite old, you should prepare to rewrite ;)

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAG2rwuONtt48xRs524uCZ0F8YqL-tgpa-nO8f_%3DWeO_%3DE-UWXg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

S Ahmed

unread,
Aug 16, 2017, 8:26:53 AM8/16/17
to rubyonra...@googlegroups.com
I know about the post request.  Just ensure when it is considered a post.xhr? request.  

On Wed, Aug 16, 2017 at 7:45 AM, Norbert Melzer <timm...@gmail.com> wrote:
(new XMLHttpRequest).open('POST', 'foo.xml', 'data') via JavaScript should do a POST request. At least according to wikipedia. But Rails 2.2 is quite old, you should prepare to rewrite ;)

S Ahmed <sahme...@gmail.com> schrieb am Mi., 16. Aug. 2017 um 04:34 Uhr:
In rails 2.2 there was checks in the code like:

    ...
    if request.xhr?
    end
    ...

end


If a HTTP POST is made, how would also be considered a XHR request?



Thanks!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CA%2BbCVssauo1C%2B%2B9b9JjRd55kS9Xs%2B6JFDshrffnPqTAjcUhBUw%40mail.gmail.com.

Hassan Schroeder

unread,
Aug 16, 2017, 10:56:17 AM8/16/17
to rubyonrails-talk
On Wed, Aug 16, 2017 at 5:25 AM, S Ahmed <sahme...@gmail.com> wrote:
> I know about the post request. Just ensure when it is considered a
> post.xhr? request.

From rack 2.0.3 lib/rack/request.rb:

def xhr?
get_header("HTTP_X_REQUESTED_WITH") == "XMLHttpRequest"
end

This is from Rails 5.1.2, btw. You can find the equivalent somewhere
in the 2.2 source, I imagine 😀

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote
Reply all
Reply to author
Forward
0 new messages