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.
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
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. [email protected]
Ah, of course. So it would be something like .
Alright, thanks.
- 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)
- 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.
alexey.Creopolis wrote:
- 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)
- 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?
Michael C. wrote:
alexey.Creopolis wrote:
- 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)
- 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.
No.
Right, but I was referring to making a regular link send a post request.
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.