Learning jsonP has been a challenge for me as I am relatively new to it. I have done my research by reading various articles but when trying out a simple example, the callback function fails to execute. Surprisingly, there are no errors or exceptions logged in the console, yet the data does not show up. Below is the code snippet that I am currently testing:
function getJSONPData(){
var url = "http://nvd3.org/examples/cumulativeLineData.json?callback=parseRequest";
var script = document.createElement('script');
script.setAttribute('src', url);
document.getElementsByTagName('head')[0].appendChild(script);
}
function parseRequest(response)
{
try
{
alert("got response");
console.log(response);
}
catch(an_exception)
{
alert('exception occured '+an_exception);
}
}
Inspecting the 'network' tab on the Chrome web console shows that the requested json file was fetched successfully with a status of "200 OK". Furthermore, the data from the requested json file can be seen in the "response" section of the network tab. Despite this, why isn't the data being displayed directly in the console when attempting to print it? Upon debugging the code, it appears that the callback method is not being triggered. I'm puzzled by this situation and wonder if I am overlooking something important. Any assistance would be greatly appreciated.