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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.