After delving into the world of JSONP callback functions, I decided to familiarize myself with the concept by researching articles.
To further understand JSONP, I uploaded a JSON file onto the server - json file
Below is the JavaScript code I used to fetch the data. The request is made from localhost to abhishekprakash.com.
var xhr;
var dataList;
xhr = new XMLHttpRequest();
xhr.open('GET', 'http://abhishekprakash.com/script/example.json?callback=func_callbk', true);
xhr.send();
func_callback = function(data){
alert(data.data.people[0].id);
}
xhr.onreadystatechange = function(){
if(xhr.readyState == 4){
console.log(dataList);
}
};
Upon checking the console, this is the response I received:
While the callback function is triggered, it does not include the JSON data. What could be the missing piece here?
Your assistance is greatly appreciated.
Thank you