javascript - Using $.getJSON correctly -
this question has answer here:
- ways circumvent same-origin policy 11 answers
i'm trying construct simple jquery function fetches json data url can't seem output. can tell me i'm going wrong?
<button id="test">test</button>
$(document).ready(function() { $("#test").click(function() { $.getjson('https://en.wikipedia.org/w/api.php?action=query&titles=main%20page&prop=revisions&rvprop=content&format=json', function(objdata) { document.write(objdata); console.log(objdata); }); }); });
it's access control / allow-origin thats tripping here. "no 'access-control-allow-origin'"
this works:
$('#test').on('click', function() { $.getjson('https://en.wikipedia.org/w/api.php?action=query&titles=main%20page&prop=revisions&rvprop=content&format=json&callback=?', function(data) { console.log(data); }); });
notice addition of &callback=?
Comments
Post a Comment