【发布时间】:2018-11-05 14:38:48
【问题描述】:
我有一个宁静的 api,当我从邮递员那里打电话时,它可以正常工作。在邮递员上,我提供以下配置以获得答案: -POST:“https://www.example.net/API/MyFunction” 我没有授权。 -标题: 内容类型:应用程序/json, 用户名:我的用户名, 密码:我的密码 -身体 生的
{"firstparameter":"firtparameter_value"}
我有一个纯 html 域,我想在其中进行一些调用并从该 api 提供数据。所以我添加了一个指向 jquery-3.3.1.js 的链接并创建了一个 ajax 调用。我尝试遵循本指南https://www.html5rocks.com/en/tutorials/cors/,但是当我运行呼叫时,我收到以下错误。 Ajax 调用:
var username = 'myusername';
var password = 'mypassword';
$.ajax({
type: 'POST',
dataType: "jsonp",
url: 'https://www.example.net/API/MyFunction',
contentType: 'text/plain',
crossDomain: true,
data:{"firstparameter":"firtparameter_value"},
xhrFields: {
withCredentials: false
},
headers: {
username: username,
password: password
},
success: function () {
error: function () {
}
});
我得到的错误是:
获取 https://www.example.net/API/MyFunction/?callback=jQuery33104247946565223606_1541427224545&firstparameter=firtparameter_value&_=1541427224546 net::ERR_ABORTED 405(不允许的方法)
【问题讨论】:
-
是否有理由需要将 dataType 设置为
jsonp而不是json?
标签: javascript jquery json ajax