Reputation: 11
I'm trying to read from this: http://api01.notaion.com/?item&id=120001462
<script type="text/javascript">
$.getJSON('http://api01.notaion.com/?item&id=120001462', function(data) {
});
</script>
I'm not sure if I need to use callback=?, neither how exactly to deal with the data. Hell I might be even mistaken somewhere else. Help.
Upvotes: 1
Views: 58
Reputation: 168
Because you want to fetch the data from a different domain, you need to use jsonp, which is automatically done by jquery when you add callback=? to the url. So you get the following result:
<script type="text/javascript">
$.getJSON('http://api01.notaion.com/?item&id=120001462&callback=?', function(data) {
console.log(data);
console.log(data.item[0].itemId); #prints 120001462
});
</script>
Upvotes: 1
Reputation: 12961
Yes this needs to use a JSONP
call, which using vanilla JavaScript would be like this:
//create a global callback function
function jsonpCallback(jsonObject){
}
function getJSONP(){
var script = document.createElement('script');
script.src = 'http://api01.notaion.com/?item&id=120001462&callback=jsonpCallback';
document.getElementsByTagName('head')[0].appendChild(script);
}
then as soon as it is called your callback would get the data from the server.
Upvotes: 0
Reputation: 193261
The API doesn't seem to support CORS. However they do support JSONP:
$.ajax({
url: 'http://api01.notaion.com/?item&id=120001462',
dataType: 'jsonp'
})
.success(function(data) {
console.log(data);
});
Upvotes: 1