表单提交和ajax提交数据的请求区别

在http请求中,我们通常会看到请求字段以query string parameters,或form data,或request payload形式发送到服务器,究竟他们有什么区别呢?下面为您揭晓答案。
一、参考链接
二、enctype是什么?
enctype是一个表单的属性,规定在发送到服务器之前应该如何对表单数据进行编码。enctype取值如下:
1 application/x-www-form-urlencoded,在发送到服务器之前,所有字符都会进行编码(空格转换为"+"加号,特殊符号转换为ASCII HEX值)。
2 multipart/form-data,不对字符编码。在使用包含文件上传控件的表单时,必须使用该值。
3 text/plain,空格转换为"+"加号,但不对特殊字符编码。
三、请求分类
1、get请求
General
Request URL: https://www.xxx.com/api/getUserInfo
Request Method: GET
Status Code: 200 OK

Query String Parameters 
username: camillehou666
tel: 17816165663
2、表单post请求
General
Request URL: https://www.xxx.com/api/getUserInfo
Request Method: POST
Status Code: 200 OK

Request Headers 
Content-Type: application/x-www-form-urlencoded 

Form Data 
username: camillehou666
tel: 17816165663
3、ajax的post请求
General
Request URL: https://www.xxx.com/api/getUserInfo
Request Method: POST
Status Code: 200 OK

Request Headers 
Content-Type: text/plain;charset=UTF-8

Request Payload
username: camillehou666
tel: 17816165663
如果不指定Content-Type,默认就是text/plain;charset=UTF-8,所以需要指定Content-Type, xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")

转载于:https://www.cnblogs.com/camille666/p/http_request_form_ajax_get_post.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值