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

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -