ajax请求中form data与request payload之间的区别

HTTP请求过程中,get请求:表单参数以name=value&name1=value1的形式附到url的后面;

          post请求:表单参数是在请求体中,也是name=value&name1=value1的形式在请求体中。

POST表单请求提交时,使用的Content-Type是application/x-www-form-urlencoded,而使用原生AJAX的POST请求如果不指定请求头RequestHeader,默认使用的Content-Type是text/plain;charset=UTF-8。

在html中form的Content-type默认值:Content-type:application/x-www-form-urlencoded

如果使用ajax请求,在请求头中出现 request payload导致参数的方式改变了 ,那么解决办法就是:

  headers: {'Content-Type': 'application/x-www-form-urlencoded'}

或者使用ajax设置:

  $.ajaxSetup({contentType: 'application/x-www-form-urlencoded'});

这样,问题就可以解决。

原文地址:https://www.cnblogs.com/wuzhuo/p/4026987.html