ajax里post 设置请求头的编码格式

我们常用的ajax形式就是post和get。post需要设置请求头,那么问题来了:

首先,为什么get不需要设置编码格式?

其次:不设置post请求头编码格式可以吗?

还有:常用的请求头编码格式有哪些?

get方法ajax请求,xhr.open把参数和url放在一块,

常见请求头格式:

json:xhr.setRequestHeader("Content-type","application/json; charset=utf-8");//内容类型

form:xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");

文本:xhr.setRequestHeader("Content-type", "text/plain; charset=utf-8");

我的演示,未完待续;

原文地址:https://www.cnblogs.com/dangdanghepingping/p/10167135.html