2

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

Bomber
  • 10,195
  • 24
  • 90
  • 167

1 Answers1

1

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?

Community
  • 1
  • 1
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • Thanks for the reply. So my eventSources should look like this: 'eventSources: [ // your event source { url: 'json-events.php', type: 'POST', error: function(data) { alert('there was an error while fetching events!' + data.msge); }, success: function(data) { var event = data.approved; if(event == "1") { alert('approved'); // do stuff else{ alert('uapproved'); // do stuff } } } ]' – Bomber Dec 20 '12 at 15:15
  • Something like this: if(event == "1") { event.title = event.title + "approved"; event.className = "approved"; } else{ event.title = event.title + "awaiting approval"; event.className = "unapproved"; } However I get event udefined error. – Bomber Dec 20 '12 at 15:27
  • Can someone also tell me how to add a comment with formatted code? thanks – Bomber Dec 20 '12 at 15:27
  • You cannot, you have to edit your original post. I based my answer on the JSON response that you put in your comment above. – Jay Blanchard Dec 20 '12 at 15:28
  • Anymore ideas folks? still stuck with this. – Bomber Dec 26 '12 at 14:53
  • 1
    You're missing a semi-colon after data.title – Jay Blanchard Dec 26 '12 at 15:39
  • Thanks very much for your reply, I cant seem to pass an ID to the click function which is causing the problem. Any ideas? Thankyou – Bomber Dec 31 '12 at 10:19
  • Shouldn't this var eventid = calEvent.id; be var eventid = calEvent.eventid; ? – Jay Blanchard Dec 31 '12 at 12:54
  • Thanks for you reply, I've edited my code if you could confirm I am on the right path that would be great. – Bomber Jan 02 '13 at 10:32
  • Without being able to connect to your JSON source it would appear that you are on the right path. – Jay Blanchard Jan 02 '13 at 13:14