javascript - jQuery JSON AJAX Request to different domain -
i'm trying make ajax request https://api.mojang.com/users/profiles/minecraft/username, should return json data (not sure if jsonp)
when click on button perform ajax request this:
http://prntscr.com/8xswr1 (google chrome console)
when double click on 'dude1?callback...' this:
which contains json data want returned, meaning making request , getting json data can't parse or information
code:
<!doctype html> <html> <head> <title>website</title> <script src="https://code.jquery.com/jquery-2.1.4.js"></script> <script> function getinfo() { username = $('#username').val(); $.ajax({ type: 'get', url: "https://api.mojang.com/users/profiles/minecraft/" + username, //crossdomain: true, datatype: 'jsonp', success: function (data) { alert(data.name); } }); } </script> </head> <body> <form> username: <input type="text" id="username" name="username"/> </form> <button onclick="getinfo();">submit</button> <span id="info"> </span> </body> </html>
also, if change 'datatype' parameter 'json' error http://prntscr.com/8xsy9e
this should return json data (not sure if jsonp)
it's json.
when click on button perform ajax request this
that's typical error trying execute json if jsonp.
when double click on 'dude1?callback...' this
yup, json. not jsonp.
also, if change 'datatype' parameter 'json' error
yup, site requesting data isn't giving site permission read using visitor's browsers.
cross-origin ajax requires site getting data co-operates provide it.
fetch data server instead.
Comments
Post a Comment