JS下的网络请求学习记录

常见post数据格式

四种常见post的数据格式

FormData对象的使用

FormData对象的使用官方文档

FileReader对象的使用

FileReader官方文档

Form表单对象的使用

Form官方文档
表单提交:事件和方法提交
Form表单&FileReader:文件的上传和读取

input type = ‘file’

HTMLElement官方文档
input type = 'file'相关属性官方文档介绍

submit方法的使用

submit官方文档

使用web应用中的文件

Using files from web applications

Using XMLHttp​Request

AJax入门官方文档
用XMLHttpRequest 发送表单信息、上传文件
Ajax请求($.ajax()为例)中data属性传参数的形式

Array数组相关的使用

array官方文档

A brief introduction to the submit methods

An html

can be sent in four ways:

  • using the POST method and setting the enctype attribute to application/x-www-form-urlencoded (default);
  • using the POST method and setting the enctype attribute to text/plain;
  • using the POST method and setting the enctype attribute to multipart/form-data;
  • using the GET method (in this case the enctype attribute will be ignored).

Now, consider the submission of a form containing only two fields, named foo and baz. If you are using the POST method the server will receive a string similar to one of the following three examples, depending on the encoding type you are using:

  • Method: POST; Encoding type: application/x-www-form-urlencoded (default):

    Content-Type: application/x-www-form-urlencoded
    
    foo=bar&baz=The+first+line.%0D%0AThe+second+line.%0D%0A
    
  • Method: POST; Encoding type: text/plain:

    Content-Type: text/plain
    
    foo=bar
    baz=The first line.
    The second line.
    
  • Method: POST; Encoding type: [multipart/form-data](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#multipartform-data):

    Content-Type: multipart/form-data; boundary=---------------------------314911788813839
    
    -----------------------------314911788813839
    Content-Disposition: form-data; name="foo"
    
    bar
    -----------------------------314911788813839
    Content-Disposition: form-data; name="baz"
    
    The first line.
    The second line.
    
    -----------------------------314911788813839--
    

However, if you are using the GET method, a string like the following will be simply added to the URL:

?foo=bar&baz=The%20first%20line.%0AThe%20second%20line.

你可能感兴趣的:(JS下的网络请求学习记录)