ajax传json参数
- 前端
- 三生万物
- 0
需要把 contentType
设置为 application/json
,然后参数使用 JSON.stringify
处理JSON字符串
var params = {
token: 'dsffjklajoaimeo122j312',
type: 'in'
};
$.ajax({
type: "POST",
url: "http://api.com/xxx",
data: JSON.stringify(params),
contentType: 'application/json',
dataType: "json",
success: function (res) {
// ...
},
});
或者设置header头实现
var params = {
token: 'dsffjklajoaimeo122j312',
type: 'in'
};
$.ajax({
type: "POST",
url: "http://api.com/xxx",
data: JSON.stringify(params),
headers: {
"Content-Type": "application/json"
},
dataType: "json",
success: function (res) {
// ...
},
});
免责申明:本站发布的内容(图片、视频和文字)以转载和分享为主,文章观点不代表本站立场,如涉及侵权请联系站长邮箱:xbc-online@qq.com进行反馈,一经查实,将立刻删除涉嫌侵权内容。