次の jquery 呼び出しを使用すると、http 405 method not allowed というエラー メッセージが表示されます。これを解決する方法を知っている人はいますか?httpsのせい?タイプGETとPUTでも試してみましたが、同じ結果でした
function make_base_auth(user, password) {
var tok = user + ':' + password;
var hash = btoa(tok);
return "Basic " + hash;
}
function createJiraIssue() {
var datos = {
"fields": {
"project":
{
"key": "HELP"
},
"summary": "Test Ticket",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
},
"assignee": { "name": "sim" }
}
};
var parameters = JSON.stringify(datos);
var req = $.ajax({
url: 'https://xxx.jira.com/rest/api/2/issue/',
type: "POST",
data: parameters,
contentType: 'application/jsonp',
dataType: 'jsonp',
async: false,
processData: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', make_base_auth(user, password));
},
error: function (errmsg) {
alert('error ocured:' + errmsg.responseText);
},
success: function (text) {
alert(text);
},
});
}
編集 contentType: 'application/json', dataType: 'json' である必要があり、405 エラーは消えます。
しかし、コードはエラー コールバックで終了します。そこのアラート機能を alert('error ocured:' + errmsg.error); に変更しました。そして、それは私にこれを与えました:エラーが発生しました:
function (){
if(!e){
var c=arguments,g,h,i,j,k;b&&(k=b,b=0);
for(g=0,h=c.length;
g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);
k&&f.resolveWith(k[0],k[1])
}return this
}
クロムでは、コンソールにエラーが表示されます: XMLHttpRequest cannot load https://xxx.jira.com/rest/api/2/issue/
。http://localhost:49592
Access-Control-Allow-Origin でオリジンが許可されていません。誰がエラーが何であるか知っていますか?