问题描述
使用以下jquery调用时,我收到一个不允许的http 405方法错误消息。
有谁知道如何解决这个问题?是由于https?我也尝试了类型为GET和PUT的结果相同
When using the following jquery call I receive a http 405 method not allowed error message.Does anybody know how to solve this? Is it due to the https? I tried it also with type GET and PUT with the same result
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错误消失。
EDITIt has to be,contentType: 'application/json',dataType: 'json'and the 405 error disapears.
但是现在代码最终出现在错误回调中。我将警报功能更改为警报('错误发生:'+ errmsg.error);
它给了我这个:
错误发生:
But now the code ends up in the error callback. I changed the alert function in there to alert('error ocured:' + errmsg.error);and it gave me this:error ocured:
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
}
在chrome中,我在控制台中收到错误:
XMLHttpRequest无法加载 https://xxx.jira.com/rest/api/ 2 /问题/
。 Access-Control-Allow-Origin不允许使用Origin http:// localhost:49592
。
有人知道错误是什么吗?
In chrome I get the error in the console:XMLHttpRequest cannot load https://xxx.jira.com/rest/api/2/issue/
. Origin http://localhost:49592
is not allowed by Access-Control-Allow-Origin.Does anybody know what the error is?
推荐答案
我不确定是否可能。你得到的错误是说你不能做跨域XMLHttp请求。您可以在中找到更多信息。
I'm not sure if it's possible. The error you got is saying that you can't do cross domain XMLHttp Request. you can find more information on this answer.
解决这个问题的一种方法是使用php(或任何其他语言)创建一个本地API,它将为jQuery提供的ajax调用提供服务。
One way to go around it, is to create a local API, using php (or any other language), that will serve the ajax calls made by jQuery.
例如,写一个将通过创建问题,然后使用javascript将此页面发布到所有需要的详细信息。
For example, write a PHP page that will create issues via the REST API, then use the javascript to post to this page all the needed details.
如果您需要任何帮助,请告诉我。
Let me know if you need any help.
编辑
使用C#执行此操作,最简单的方法可能是使用。
to do it using C#, The easiest way ill probably be using something like JiraRestClient.NET.
如果你喜欢自己编码,这里有一些关于。
If you prefer to code it yourself, here is some info about connecting to Jira using REST.
这篇关于通过REST api和jquery 405方法创建Jira问题是不允许的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!