1

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.

2
  • What's the problem? Is data empty? What isn't working? Commented Feb 23, 2014 at 12:30
  • Blocked by same origin policy -> jsfiddle.net/vSf8S Commented Feb 23, 2014 at 12:31

3 Answers 3

1

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);
});

Demo: http://jsfiddle.net/h4shZ/

Sign up to request clarification or add additional context in comments.

Comments

1

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>

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.