1

I want to get from jira a list of all tickets , I used XMLHttpRequest(), but I get an error when I try to parse the response with json (unexpected end of data at line 1 column 1 of the JSON data), this is my code:

<script type="text/javascript">
function request(){
  var xhr = new XMLHttpRequest();
  baseURL="...jira/rest/api/2/...";
  xhr.open("GET", baseURL, true);
  xhr.setRequestHeader("Authorization", "Basic "+btoa("userName:password"));
  xhr.setRequestHeader('Content-Type', 'application/json');
  xhr.send();
  var response = JSON.parse(xhr.responseText);
  document.write(response);
}
request();
</script>
1

1 Answer 1

2

xhr.responseText will be undefined at that point.

You have to wait for the response before trying to read the responseText.

xhr.send();
xhr.addEventListener("load", function () {
    var response = JSON.parse(xhr.responseText);
    document.write(response);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.