Bomber
Bomber

Reputation: 10947

Cannot render events from JSON feed

Updated:

Many thanks for your reply, I now have this code:

  success: function (data) {

      $.each(data, function (id, event)

      var test = data.approved
      if (test == "1") {
          alert('approved')
      }

      );
  }

Here is the sample of my JSON:

{"id":"174","title":"John Smith","start":"2013-04-03 00:00:00","end":"2013-04-05 00:00:00","fullname":"John Smith","approved":"1"}, {"id":"175","title":"John Smith","start":"2012-12-25 00:00:00","end":"2012-12-27 00:00:00","fullname":"John Smith","approved":"0"}, {"id":"176","title":"John Smith","start":"2012-12-28 00:00:00","end":"2012-12-28 00:00:00","fullname":"John Smith","approved":"1"}, {"id":"177","title":"John Smith","start":"2012-12-29 00:00:00","end":"2012-12-29 00:00:00","fullname":"John Smith","approved":"0"}, {"id":"178","title":"John Smith","start":"2012-12-21 00:00:00","end":"2012-12-22 00:00:00","fullname":"John Smith","approved":"1"}

Could you please advise as to how I can get the approved alert if the event has been approved in the JSON?

Many thanks once again

Upvotes: 2

Views: 221

Answers (1)

Jay Blanchard
Jay Blanchard

Reputation: 34406

You should be able to access the data like this -

success: function(data) {    
    var event = data.approved;
    if(event == "1") {
        // do stuff 
    }
}

Here is the code that should work -

success: function(data) {
    $.each(data, function() {
        $.each(this, function(k, v) {
            if((k == 'approved') && (v == '1')) {
                alert('approved!')
            } 
        });
    });
}

Have a look at this jQuery loop over JSON result from AJAX Success?

Upvotes: 1

Related Questions