Ismar Slomic Ismar Slomic - 6 months ago 151
jQuery Question

Calling JIRA REST Api from Javascript in local HTML file

I´m trying to call JIRA REST Api from javascript in HTML running locally by using jQuery.ajax function like below:

$.ajax({
type: "GET",
url: "http://jira.myhost.com/rest/api/2/issue/AB-123",
dataType: "json",
contentType: "application/json",
async: false,
beforeSend: function (xhr) {
var base64 = "YWRtaW46YWRtaW4";
xhr.withCredentials = true;
xhr.setRequestHeader("Authorization", "Basic " + base64);
}
})
.fail(function (error) {
console.log(error.statusText)
});


When opening HTML file in Chrome I get following error in console:

NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://jira.myhost.com/rest/api/2/issue/AB-123'.


However, I can successfully access the same JIRA REST Api by using CURL locally:

curl -D- -X GET -H "Authorization: Basic YWRtaW46YWRtaW4" -H "Content-Type: application/json" "http://jira.myhost.com/rest/api/2/issue/AB-123"


Any tip on how to get this working from JavaScript?

Answer

Thanks @Andreas!

Solution

open /Applications/Google\ Chrome.app/ --args --disable-web-security

Note, this is just a temporary solution on CORS issues locally on my machine and is only used for testing purpose.

Comments