post提交数据四种常见的content-type取值:
1.application/x-www-form-urlencoded :
最常见的 POST 提交数据的方式
2.multipart/form-data :
使用表单上传文件时,传递这个值
3.application/json :
用来告诉服务端发送的数据是序列化后的 JSON 字符串
4.text/xml :
使用 HTTP 作为传输协议,XML 作为编码方式的远程调用规范
<script>
//页面加载事件
$(function () {
$("#btn").click(function () {
//发送ajax请求
var url = "user/testAjax";
var params = {"username":"liangge", "password":"123", "age":18};
$.ajax({
url:url,
data:params,
type:"post",
success:function (resultData) {
//成功后的回调函数
console.log(resultData);
console.log(resultData.username);
console.log(resultData.password);
console.log(resultData.age);
},
dataType:"json",
contentType: 'application/json;charset=UTF-8'
});
});
});
</script>