Hi I am trying to use ONLY JavaScript
and HTML
to read the json
object from a URL. I am using the following code:
function getJSONP(url, success) {
var ud = '_' + +new Date,
script = document.createElement('script'),
head = document.getElementsByTagName('head')[0]
|| document.documentElement;
window[ud] = function(data) {
head.removeChild(script);
success && success(data);
};
script.src = url.replace('callback=?', 'callback=' + ud);
head.appendChild(script);
}
getJSONP('http://webURl?&callback=?', function(data){
console.log(data);
});
As you would have guessed I am getting Not at same origin as the document, and parent of track element does not have a 'crossorigin' attribute. Origin 'null' is therefore not allowed access.
FYI the server returns JSON data and doesnot have callback function.
Cheers for your help.