使用xmlhttprequestobject调用api时出错。 JSON输入意外结束

时间:2019-06-13 11:04:37

标签: javascript xmlhttprequest

我想调用基本身份验证Rest API。同时使用xmlhttprequest对象调用rest api。我收到了有效的回复,但收到了这样的消息

Uncaught SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at XMLHttpRequest.xhttp.onreadystatechange

js代码

function getdata(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      var response = JSON.parse(xhttp.responseText);//serialization
      var dataframe = response.dataFrame;

      document.getElementById("pir_Status").innerHTML=dataframe;
    }
};
    xhttp.open("GET", "restapi", true);
    xhttp.setRequestHeader("Content-type", "application/json");
    xhttp.setRequestHeader("Authorization", "Basic dmMw==");
    xhttp.send();
}

0 个答案:

没有答案