我的参数中有数组:
比如var req = {
ids: [1, 2, 3]}
ajax 写法必须把 req 进行字符串化,然后设置 contentType: "application/json"
后台才可以正常的接受到传来过来的数组
$.ajax({
url: '/.../delete-by-ids',
type: 'post',
data: JSON.stringify(req),
dataType: 'json',
contentType: "application/json",
traditional:true,
success: function (data) {
callback(data);
},
error: function (data) {
$.dialog("错误");
}
})
我已经设置了 JSON.stringfy(req),那么 req 按理来说现在应该已经是 string 类型了,为什么 contentType 却还是要设置为 application/json