Making a POST request requires JavaScript?


#1

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.


#2

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


#3

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


#4

Ah, of course. So it would be something like .

Alright, thanks.


#5

On 4/22/07, Michael C. removed_email_address@domain.invalid wrote:

Ah, of course. So it would be something like .

No.


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com


#6
  1. POST method primary used in <form method="POST> does not require
    javascript (unless you are using and want change
    it to “POST” by some conditions)
  2. POST method can be used with regular 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.


#7

alexey.Creopolis wrote:

  1. POST method primary used in <form method="POST> does not require
    javascript (unless you are using and want change
    it to “POST” by some conditions)
  2. POST method can be used with regular 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?


#8

Michael C. wrote:

alexey.Creopolis wrote:

  1. POST method primary used in <form method="POST> does not require
    javascript (unless you are using and want change
    it to “POST” by some conditions)
  2. POST method can be used with regular 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 tag, in other word, link_to only create a hyperlink.
I don’t see how one can construct a post request with a hyperlink.


#9

No.

Right, but I was referring to making a regular link send a post request.


#10

I don’t see how one can construct a post request with a hyperlink.

I just decided to go and simply try it :slight_smile: 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.