问题描述
点击提交按钮时会发生什么?让我有一个位于 http://example.com/
URL 上的表单,其中包含两个 input
元素,如下所示:
What happens when submit button is clicked? Let I've a form which located on an http://example.com/
URL with the two input
elements like this:
<form method="get">
<input type="text" id="field1" name="namefield1"/>
<input type="text" id="field2" name="namefield2"/>
<input type="submit" value="submit"/>
</form>
在我的特定情况下,什么实际获取请求将发送到 http
-server?
What actually get request will be sent to an http
-server in my specific case?
推荐答案
表单将提交到服务器,浏览器将重定向到浏览器的当前地址,并将输入字段的值作为查询字符串参数附加.
The form will be submitted to the server and the browser will redirect away to the current address of the browser and append as query string parameters the values of the input fields.
就HTTP协议而言,将发送以下GET请求HTTP请求:
In terms of the HTTP protocol the following GET request HTTP request will be sent:
GET http://example.com/?namefield1=value1&namefield2=value2 HTTP/1.1
Host: example.com
由于您的 缺少
action
属性,浏览器将通过附加值作为查询字符串参数简单地重定向到当前 url.所以如果这个表单是在提交后从 http://example.com/foo.php
加载的,浏览器会重定向到 http://example.com/foo.php?namefield1=value1&namefield2=value2
其中 value1
和 value2
将是用户在相应输入字段中输入的值.
Since your <form>
is missing an action
attribute, the browser will simply redirect to the current url by appending the values as query string parameters. So if this form was loaded from http://example.com/foo.php
after submitting it, the browser will redirect to http://example.com/foo.php?namefield1=value1&namefield2=value2
where value1
and value2
will be the values enetered by the user in the corresponding input fields.
您也可以使用浏览器内置的调试工具或 Fiddler
检查发送到服务器的确切有效负载.
Also you might use your browser's built in debugging tools or Fiddler
to inspect the exact payload that gets sent to the server.
这篇关于单击提交按钮时会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!