Aerovistae Aerovistae - 3 months ago 6
Ajax Question

What causes the user to go to new a page when they submit a form, and can it be done in JavaScript?

You supply the

properties on a form, and then when it's submitted, it completes that HTTP
using the url specified in
. The end result takes the user to a new page, the page returned by the server in response to a POST (or whatever) to that target URL.

What causes this redirect? Is it an intrinsic property of how HTML form elements work, or is it just a redirect header in the HTTP response?

I'm trying to reproduce that effect with an ajax POST, without just manually writing a line of JS to do the redirect~ I want it to happen automatically, the same way.

Is submitting a form essentially the same as going to the url

That can't be right, since the browser bar is always a GET request.


Form's action attribute serves a role of navigation URL, a.k.a. "plan to navigate". target attribute defines where to load that response returned by the server.

So yes, that is "an intrinsic property of how HTML form elements work".

Algorithm of handling form submission is defined in HTML4 and HTML5 forms specifications.

Submitting the form is essentially an ordinary URL navigation (by <a href> elements) but with automatic parameters gathering that go either into final navigation URL as parameters ( <form method="get"> ) or as request body parameters ( <form method="post"> )