表单提交方法post和get区别

Form Methods
When creating a form that will submit data to a Web server, one of the
attributes you must specify is method. The method attribute can be set to either
get or post.
If the method is set to get, the values in the form are passed at the end of the
URL specified in the action attribute. The amount of data that can be sent with
the get method is limited to a maximum length of 4 KB.

表单方法
当我们创建了一个表单用于提交数据给服务器,有一个必须被提交的属性那就是方法。表单提交的方法有两种一种是get方法一种是post方法
如果选择的是get方法,那么这个表单的数据是通过在action属性中的url后面追加参数来提交数据。数据量的大小被限制在4K以内。
而post方法实际上是提交这个HTML文档。打个比方好比考试完了以后,学生拿的是卷子,家长看的是成绩。当然给家长看卷子也只是瞟一样成绩了,告诉学生成绩但是他不知道错在哪里,呵呵。

下面是一个html文档,提交之后可以看到地址后面跟了一些参数
譬如:http://localhost/asp/temp/20070328/form.html?product=shoes&price=69.95
因为是纯静态html所以不能处理表单数据了。
Here is the HTML document with a form using the get method:

< HTML >
< SCRIPT  TYPE ="text/javascript" >
function getPrice( obj) {
switch (obj.value) {
case 'shoes':
//Accessing elements ARRAY WITH index
document.forms[0].elements[1].value=69.95
break
case 'shirt':
//Accessing elements array with index value
document.shopping.elements['price'].value=19.95
break
case 'pants':
//Accessing elements array with a tag name
document.forms['shopping'].price.value=29.95
break
case 'sox':
document.shopping.price.value
=1.95
break
}

}

</ SCRIPT >
< BODY >
< H1 >  Example of Using Get Method </ H1 >
< FORM  name =shopping  method =Get  >
< Select  name =product  onclick =getPrice(this) >
< option  value =shoes > shoes </ option >
< option  value =shirt > shirt </ option >
< option  value =pants > pants </ option >
< option  value =sox > sox </ option >
</ select >
< INPUT  TYPE =TEXT  VALUE =0  name =price >
< BR >< INPUT  TYPE =SUBMIT >
</ FORM >
</ BODY >
</ HTML >

 


The get method passes data to the Web server by adding a string to the end of
the URL. The string begins with a question mark and contains pairs of tag
names followed by the value for the tag. The get method will not place any
data into the string if the tag does not have a value assigned to the name
attribute.

get方法给服务器传递值是在url后面追加字符串。这个字符串是以问号?以及包含一对或多对键|值,如果表单元素的标签中不存在对应的键名(name属性) 则赋的指是无效的。

If the method is set to post, the tag name and tag values in the form are passed
to the URL specified in the action attribute in the body section of the request.
There is no limit to the amount of data that can be passed using the post
method. Here is an example of a form using the post method:

如果方法是post,表单中的标签名称和值通过action,把请求夹带在body区域传递给给url。post的数据量是没有限制的。这是一个例子

< HTML >
< BODY >
< H1 >  Example of using Post method </ H1 >
< FORM  name =login  method =post  >
Enter User Name
< INPUT  TYPE =Text  name =uname >
Enter Password
< INPUT  TYPE =Password  name =upassword >
< BR >< INPUT  TYPE =SUBMIT  Value =Login >
</ FORM >
</ BODY >
</ HTML >  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值