for the GET method on URL https://futuregroupb.atlassian.net/rest/api/2/issue/LHEL-24 i get response from browser (cookie based), curl command as well as my ajax jquery code.
However when i hit the same URl for POST method i get an error "XMLHttpRequest cannot load the URL Response for preflight has invalid HTTP status code 403"
However I get a response on the curl command perfectly fine
curl -D- -u admin:Welcome@123 -X POST --data @"/root/input.json" -H "Content-Type: application/json" https://futuregroupb.atlassian.net/rest/api/2/issue/
Cross origin is also not a problem, i am using a CORS extension to sort that matter.
Below is my code:
$("#createbtn").click(function(){
var val1 = $("#Summary").val();
var val2 = $("#Des").val();
var sendInfo = {
fields: {
project:{ id: '10000' },
summary: val1,
description: val2,
issuetype: {
id: '10101'
}
}
};
$.ajax({
type: 'POST',
contentType: 'application/json',
dataType: 'json',
data: sendInfo,
url: 'https://futuregroupb.atlassian.net/rest/api/2/issue/',
beforeSend: function (xhr){
xhr.setRequestHeader('Authorization', make_base_auth("admin", "Welcome@123"));
},
success: function (data) {
console.log('success', data );
alert(sta);
},
error: function (data, status, error) {
console.log('error', data, status, error);
}
});
})
function make_base_auth(user, password) {
var tok = user + ':' + password;
var hash = btoa(tok);
return "Basic " + hash;
}
Please help.
Thanks Ramneek