I am trying to add a comment in JIRA issue using javascript. But its not working. Can someone help me fix this?
<!doctype html>
<html>
<script type="text/javascript">
var usr = 'user1';
var psw = 'pass1';
var sendComment = {"body" : "comment1"};
$("button").on("click",function(){
$.ajax({
type: "POST",
url: "https://xxxxx.atlassian.net/rest/api/2/issue/KEY-123/comment",
dataType: "JSON",
headers: {"Authorization": "Basic " + btoa(usr + ":" + psw)},
data: JSON.stringify(sendComment),
success: function(result) {console.log('success');},
error: function(req, status, err) {console.log('Something went wrong', status, err);}
});
});
</script>
<button>Update JIRA</button>
<body>
</body>
</html>
This will work for you:
var usr = 'user1';
var psw = 'pass1';
var data = JSON.stringify({
"body": "comment test"
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log('success');
}
});
xhr.open("POST", "https://xxxxx.atlassian.net/rest/api/2/issue/KEY-123/comment");
xhr.setRequestHeader("authorization", "Basic " + btoa(usr + ":" + psw));
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
Great stuff! Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.