2

I'm trying to modify the flickr example from: http://api.jquery.com/jquery.getjson/ to use the Sqoot API instead. I'm using this example to learn about jquery. Can somebody please tell me why it works with flickr but not sqoot?

I changed my api key to MYKEY, but they will give you one instantly by just providing an email and making a password.

Thanks.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>SQOOT</title>
  <style>
    img {
      height: 100px;
      float: left;
    }
  </style>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
  <div id="images"></div>
  <div id="titles"></div>
  <div id="images2"></div>
  <script>
    (function() {
      var SqootAPI = "http://api.sqoot.com/v2/deals?api_key=MYKEY&callback=?";
      $.getJSON( SqootAPI, {
        location: "miami"
      })
      .done(function( data ) {
        $.each( data.deals, function( i, item ) {
          $( "<img>" ).attr( "src", item.deal.image_url ).appendTo( "#images" );
          if ( i === 3 ) {
            return false;
          }
        });
      });
    })();
  </script>
</body>
</html>

1 Answer 1

1

Actually they're return a JSON String and not a JSONP return value.

It should look like this:

yourCallbackFunction({Object})

But they're just return JSON data:

{ result: [ ] }

That's why you're getting a message in your console:

SyntaxError: missing ; before statement

And if you dont use a callback function you get the same origin policy ofc.

You should maybe contact the support to tell them you that there's something wrong with their API.

edit:

http://api.sqoot.com/v2/deals?api_key=YourKey&callback=pickles

http://docs.sqoot.com/v2/overview.html

There you can also see that it doesn't return the expected value they wrote in their documentation ( pickles({ "deals": [] }) ) which would be valid jsonp.

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

5 Comments

sorry. you're right. executed it locally so ofc i didnt get problems with the same origin policy ;) . Edited my answer.
I'm sorry. I don't understand. They (flickr and sqoot) both return json data in nearly the same format when typed into a url. Are you using it as I posted it (with MYKEY) as the key? That was just a placeholder. Thanks for your help.
NEARLY the same format right. When you look at what flickr returns you will see that it wraps the json data in a callback function: jQuery1102004985846984...({...}) Thats valid jsonp. It expects a callback function with a json object as a parameter. What the sqoot API returns is just: {"query":{"total"... So it doesn't wrap the json data in a callback function. JSONP != JSON I hope i could help.
Now I understand. You were a great help. Thanks again.
The "categories" API works: api.sqoot.com/v2/categories?api_key=YourKey&callback=myfct you can see that it wraps the information with the function "myfct". that doesn't seem to work right with the "deals" API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.