2

I can't seem to get jquery to return anything from the groupon API.

When I check in apigee I can do a simple get request to get all divisions.

But when I try in JSFiddle it ain't working

$.get('https://api.groupon.com/v2/divisions.json?client_id=b91d375e38147f3c1e0339a3588d0b791c190424', function(data) {
        console.log(data);
    });

The $.get above returns a response that's empty.

$.getJSON("https://api.groupon.com/v2/divisions.json?client_id=b91d375e38147f3c1e0339a3588d0b791c190424&jsoncallback=?", function(json) {
        console.log(data);
    });

This one returns an error

invalid label
[Break On This Error] {"divisions":[{"id":"abbotsford","name...owCustomerEnabled":false,"areas":[]}]}

What am I doing wrong here?

Here is the JSFIDDLE :

http://jsfiddle.net/fMzeK/5/

Stofke
  • 2,928
  • 2
  • 21
  • 28

1 Answers1

1

You will need JSONP because it will be cross domain:

$.ajax({
    url: 'https://api.groupon.com/v2/divisions.json?client_id=b91d375e38147f3c1e0339a3588d0b791c190424', 
    dataType: 'jsonp',
    success: function(data) {
        $('#result').html(data);
        alert(data.divisions);
}});
Joe
  • 80,724
  • 18
  • 127
  • 145
  • it seems to return the data alright but it still gives this warning :Resource interpreted as Script but transferred with MIME type application/json. – Stofke Jun 28 '11 at 22:01
  • Javascript can be transferred with pretty much any encoding. You shouldn't worry to much about it :) – Lime Jun 28 '11 at 22:09