<form id = "myForm" action="localhost" method="get">
<input name="liftString" type="text">
<input type="submit">
</form>
This form doesn't do anything when clicking the submit button. I'm not redirected to localhost
.
If I change the action
attribute to "/localhost"
it tries to take me to file:///localhost?liftString=d
when running the form locally.
If I change action
to "http://localhost"
, it correctly takes me to http://localhost/?liftString=f
.
What is happening in the form example posted? Why does the form do nothing when I click submit?
CLARIFICATION: I understand what's going on when action="/localhost"
and action="https://localhost"
. What I don't understand is why NOTHING happens when I have action="localhost"
.
A URL that doesn't start with a scheme (such as http://
) or the scheme-relative indicator (//
) is relative to the current URL (unless overridden with <base>
.
So the browser takes the URL of the current page, strips off everything after the last /
in it, appends the relative URL (localhost
) then adds a query string after that.
Since you are using a file://
scheme to view the page, the form would submit to a file on your computer with no HTTP server to process the form data. Since the file localhost
doesn't exist, the browser just ignores the form submission request instead.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments