I am having a little trouble with parsing the data. When i add JSON.parse(this.responseText) and this.status == 200 on the if statement my code seem to not work. When I take them off it works and I get the alert that it's a success. Not sure what I am doing wrong or maybe I am doing it completely wrong lol any help will be greatly appreciated! I am using Yelp API.
Here is my code:
xhr.withCredentials = true;
xhr.onreadystatechange = function() {
if(this.readyState == 4) {
console.log(this.responseText);
//let data = JSON.parse(this.responseText);
alert("Success!");
//display(data);
}
};
xhr.open("GET", "https://api.yelp.com/v3/businesses/search?term=" + resname.value + "&location=" + locationname.value+"&limit=5");
xhr.setRequestHeader("Authorization", "Bearer <MY API KEY WILL BE HERE>");
xhr.send();
error when I parse:
Unexpected end of JSON input
at JSON.parse (<anonymous>)
at XMLHttpRequest.xhr.onreadystatechange