Forum: Ruby on Rails Making a POST request requires JavaScript?

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.
Michael C. (Guest)
on 2007-04-23 02:41
From the Agile Rails book:

"Why do we check for an HTTP POST request? It’s a good habit to get
into.
Requests that change the server state should be sent using POST, not GET
requests. That’s why we overrode the link_to defaults in the form and
made
it generate a POST. But that works only if the user has JavaScript
enabled.
Adding a test to the controller finds this case and ignores the
request.)"

Can someone confirm this or am I way off in my interpretation? I had no
idea sending a POST requires JavaScript to be enabled.
Ben M. (Guest)
on 2007-04-23 06:02
(Received via mailing list)
They mean that they're doing javascript trickery to make a hypertext
link submit a form. Links normally send a GET request.

So no, POST requests don't *require* javascript... but the normal way in
which they're issued from a browser is by submitting a form, not by
clicking a link.

b
Eden L. (Guest)
on 2007-04-23 06:05
(Received via mailing list)
Sending a POST request as a result of clicking a link requires
Javascript.  Sending a POST from a form doesn't.

On Apr 23, 6:41 am, Michael C. <removed_email_address@domain.invalid>
Michael C. (Guest)
on 2007-04-23 07:27
Ah, of course. So it would be something like <a href="#"
action=".......">.

Alright, thanks.
Rick O. (Guest)
on 2007-04-23 07:35
(Received via mailing list)
On 4/22/07, Michael C. <removed_email_address@domain.invalid> wrote:
>
> Ah, of course. So it would be something like <a href="#"
> action=".......">.

No.  <form action="..." method="post">


--
Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
Michael C. (Guest)
on 2007-04-23 10:12
> No.  <form action="..." method="post">

Right, but I was referring to making a regular link send a post request.
alexey.Creopolis (Guest)
on 2007-04-23 14:15
(Received via mailing list)
1. POST method primary used in <form method="POST> does not require
javascript (unless you are using <form method="GET"> and want change
it to "POST" by some conditions)
2. POST method can be used with regular <a href="#"> using javascript,
mostly in AJAX requests,.

"link_to" create GET request.
"link_to_remote" create POST request with AJAX and yes it will be look
like "#" unless you describe otherwise.
Michael C. (Guest)
on 2007-04-23 21:01
alexey.Creopolis wrote:
> 1. POST method primary used in <form method="POST> does not require
> javascript (unless you are using <form method="GET"> and want change
> it to "POST" by some conditions)
> 2. POST method can be used with regular <a href="#"> using javascript,
> mostly in AJAX requests,.
>
> "link_to" create GET request.
> "link_to_remote" create POST request with AJAX and yes it will be look
> like "#" unless you describe otherwise.

Could a POST request not also be created with link_to :method => :post?
Would that not be the more 'appropriate' option when not using AJAX?
Wai T. (Guest)
on 2007-04-23 21:26
Michael C. wrote:
> alexey.Creopolis wrote:
>> 1. POST method primary used in <form method="POST> does not require
>> javascript (unless you are using <form method="GET"> and want change
>> it to "POST" by some conditions)
>> 2. POST method can be used with regular <a href="#"> using javascript,
>> mostly in AJAX requests,.
>>
>> "link_to" create GET request.
>> "link_to_remote" create POST request with AJAX and yes it will be look
>> like "#" unless you describe otherwise.
>
> Could a POST request not also be created with link_to :method => :post?
> Would that not be the more 'appropriate' option when not using AJAX?

That wouldn't be feasible unless you are using Javascript.  link_to
create a <a href> tag, in other word, link_to only create a hyperlink.
I don't see how one can construct a post request with a hyperlink.
Michael C. (Guest)
on 2007-04-23 23:31
> I don't see how one can construct a post request with a hyperlink.

I just decided to go and simply try it :) There's a eureka moment.

var f = document.createElement('form'); f.style.display = 'none';
this.parentNode.appendChild(f); f.method = 'POST'; f.action =
this.href;f.submit();return false;"

It creates some elaborate code for an 'onclick' event.
This topic is locked and can not be replied to.