tags:

views:

31

answers:

3

SO I am using GROUPON API to grab their deals, I am also using jquery's get to get a json response. This is my jquery

    $.get('http://api.groupon.com/v2/deals.json',
                       {
                         division_id:'boston',
                         client_id:'mykey',
                       },
              function(deals){
                                      $('#response').html(deals.soldQuantity);
              }, 'json');

After this, I do not get a response. I have checked entering the web request manually and it does work. Am I missing something? thanks

A: 

XSS (cross site scripting) issues?

Detect
could you please expland on this, I am a newbee. thanks
El Fuser
browser security may not allow JS to fetch URLS from a different TLD. workaround may be doing it in a server side script like PHP before sending to JS.
Detect
A: 

I was able to use your code and got a response fine. The error you are experiencing is related to how you handle the results.

Change:

function(deals){ 
    $('#response').html(deals.soldQuantity); 
}, 

to

function(results){ 
    // Assuming you only want the first deal
    $('#response').html(results.deals[0].soldQuantity); 
}, 

Please note, this does not have any error handling if you don't get any results back. I'm not familiar enough with the API to know whether that's feasible or not.

bendewey
Where did you use his code and get a response? This would be blocked in every major browser...the issue is the request itself, the response will be null.
Nick Craver
I ran it locally in a test html file.
bendewey
Thanks @Nick, total oversight. I just deployed it to a test server and I got the ever popular 'Access Denied' error.
bendewey
I also tried running it, but still no response. I will investigate the request issue.
El Fuser
+1  A: 

You're trying to access a resource on a remote domain with an XmlHttpRequest, which is by default blocked for security reasons by the Same Origin Policy. You need to use JSONP to get the JSON data in this way...but unfortunately it looks like the API you're hitting doesn't support this.

Your only option may be to proxy the request through your own domain, or something like Yahoo Pipes.

Nick Craver