Ajax进行post请求时

您所在的位置:网站首页 post报错415 Ajax进行post请求时

Ajax进行post请求时

#Ajax进行post请求时| 来源: 网络整理| 查看: 265

本来想用Ajax进行一个小小的请求测试:

function test() { $.ajax({ type: "POST", async: false, url: "https://10.8.62.231:28001/api/inv-basic/v1/mes/ex_querier?csrftoken=e80b771c0de9fafb9910fb9161233122", data: [{ "key": "displayName", "value": ["N3"] }, { "key": "hasLabel", "value": ["1"] }], success: function (data) { console.log(data); } })

无奈直接报错:

415 (Unsupported Media Type)

查询资料发现没有设置contentType,

1.Ajax请求时没有设置Content-Type为Json。 2.发送的请求内容不要转成JSON对象,直接发送JSON字符串即可,否则就415错误!

改代码:

function test() { $.ajax({ type: "POST", async: false, url: "https://10.8.62.231:28001/api/umebn-inv-basic/v1/mes/ex_querier?csrftoken=e80b771c0de9fafb9910fb9161233122", contentType: 'application/json', data: '[{"key": "displayName", "value": ["NE32003"]}, {"key": "hasLabel", "value": ["1"]}]', success: function (data) { console.log(data); } })

搞定!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3