【发布时间】:2016-09-01 03:47:33
【问题描述】:
我在使用 JQuery 发布数据时遇到问题。当我通过 Chrome Extension Postman 执行此操作时,它工作正常。
我的代码
var request = $.ajax({
url: 'http://pankajserver.in/api/SaveRoleApi',
type: "POST",
data: {Role : "wsed"},
async: true,
contentType: "application/json; charset=utf-8",
"X-Requested-With": "XMLHttpRequest"
});
request.done(function(msg) {
debugger;
});
request.fail(function(jqXHR, textStatus) {
debugger;
});
网址:http://pankajserver.in/api/SaveRoleApi
内容类型:“应用程序/json;charset=utf-8”
X-Requested-With: "XMLHttpRequest"
使用 Postman Chrome 扩展程序发布数据时工作正常。截图如下
【问题讨论】:
-
请您在控制台中看到的错误,或者使用 ajax 调用它时的结果。
-
控制台中显示的状态码是什么??
-
当您使用对象作为
data:选项时,它使用Content-type: application/x-www-form-urlencoded发送参数。它不能自动发送 JSON,如果你需要这样做你需要调用JSON.stringify()。