javascript - Using $.getJSON correctly -


this question has answer here:

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

Popular posts from this blog

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

sql server - SQL Query returns one result, does not return 0 or NULL result -