jquery ajax怎么可以直接传数组数据到后端?还是不能啊。每次我传数组比如{test:[1,2,3]}到后台服务器,test会变成test[],导致后端无法拿到数据,请求指点,谢谢大家。
$.ajax({
method: "POST",
url: uri,
dataType: "json",
contentType: 'application/x-www-form-urlencoded',
data: {test:[1,2,3]},
processData: false,
headers: {
'X-Auth-Token': token
}
}
方法一
$.param(data, true);
方法二
更简单,ajax的时候加上traditional: true。