我想调用基本身份验证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();
}