1
votes

I'm trying to get statistics from sendgrid by using getJSON(). Their JSON feed reads:

[{"date":"2009-06-20",
"requests":12342,
"bounces":12,
"clicks":10223,
"opens":9992,
"spamreports":5,
"unique_clicks":3,
"unique_opens":6,
"blocked":7},

{"date":"2009-06-21",
"requests":32342,
"bounces":10,
"clicks":14323,
"opens":10995,
"spamreports":7,
"unique_clicks":3,
"unique_opens":9,
"blocked":4},

{"date":"2009-06-22",
"requests":52342,
"bounces":11,
"clicks":19223,
"opens":12992,
"spamreports":2,
"unique_clicks":5,
"unique_opens":2,
"blocked":8}]

This is the jquery code to render it into the browser, but nothing is showing up?

    $(document).ready(function(){
    var stats = "https://sendgrid.com/api/[email protected]&api_key=secureSecret&days=2"

    $.getJSON(stats, function(key, value) {
                $('', {
                    id : 'sg_stats',
                    html : '
  • ' + key + '
  • ' + value '
  • ' }).appendto('body'); }); });

    I'm using this in Rails 3. I tested a flickr feed and that worked, so jQuery runs in rails.

    Do I need a success function on the getJSON() call?

    1

    1 Answers

    0
    votes

    $.getJSON() does not provide those arguments in the callback.

    Instead, wrap it with $.each().