单击提交按钮时会发生什么情况 [英] What happens when submit button is clicked

查看:148
本文介绍了单击提交按钮时会发生什么情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<点击提交按钮时会发生什么?让我有一个表单,它位于 http://example.com/ URL上,其中包含两个 input 元素像这样:

 < form method =get> 
< input type =textid =field1name =namefield1/>
< input type =textid =field2name =namefield2/>
< input type =submitvalue =submit/>
< / form>

实际获取请求的内容将发送到 http -server在我的具体情况下?

解决方案

表单将被提交给服务器,浏览器将重定向到浏览器的当前地址,并追加输入字段的值作为查询字符串参数。

就HTTP协议而言,将发送以下GET请求HTTP请求:

  GET http://example.com/?namefield1=value1&namefield2=value2 HTTP / 1.1 
主机:示例.com

由于您的< form> 缺少一个 action 属性,浏览器将通过附加值作为查询字符串参数来重定向到当前url。因此,如果此表单在提交后从 http://example.com/foo.php 加载,浏览器将重定向到 http:// example.com/foo.php?namefield1=value1&namefield2=value2 其中 value1 value2 将是用户在相应输入字段中输入的值。

另外,您也可以使用浏览器内置的调试工具或 Fiddler 检查发送到服务器的精确有效负载。


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>

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.

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

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.

Also you might use your browser's built in debugging tools or Fiddler to inspect the exact payload that gets sent to the server.

这篇关于单击提交按钮时会发生什么情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆