2

更新:

非常感谢您的回复,我现在有这个代码:

  success: function (data) {

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

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

      );
  }

这是我的 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","标题":"约翰·史密斯","开始":"2012-12-28 00:00:00","结束":"2012-12-28 00:00:00","全名":"约翰·史密斯" ,"批准":"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","全名":"约翰·史密斯","批准":"1"}

如果事件已在 JSON 中获得批准,您能否告知我如何获得批准的警报?

再次感谢

4

1 回答 1

1

您应该能够像这样访问数据 -

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

这是应该工作的代码 -

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

看看这个来自 AJAX Success 的 JSON 结果的 jQuery 循环?

于 2012-12-20T15:07:06.000 回答