weixin_33690367 2014-06-10 11:07 采纳率: 0%
浏览 196

操作数中无效的“ in”

I send the request to server using jquery $.ajax and it returns JSON.

$.ajax({
  url: 'moreMonth.ajax',
  data: { startIndex: id },
  success: function(data) {
    $.each(data, function(k, v) {
      alert(k + ':' + v); 
    });
  }
});

But I've got an error

invalid 'in' in operand a

As far as I can understand - is it a problem with success block?

Log:

"[
  {"name":"Advanced Complexity Theory.rar","size":672398,"present":true,"display":false,"publisherId":1,"downloadDate":"Jun 9, 2014 11:05:28 AM","id":11},
  {"name":"Algorithms and Complexity, Internet Edition.rar","size":971299,"present":true,"display":false,"publisherId":1,"downloadDate":"Jun 9, 2014 11:05:28 AM","id":12}
]"
  • 写回答

2条回答 默认 最新

  • weixin_33691700 2014-06-10 11:11
    关注

    You are trying to iterate over a string, that is causing this error

    variable data is string, try converting that to an array.

    Try using $.parseJSON(data)

        $.ajax({
                   url: 'moreMonth.ajax',
                   data: { startIndex: id },
                   success: function(data) {
                       data = $.parseJSON(data);
                       $.each(data, function(k, v) {
                          alert(k + ':' + v); 
                       });
                   }
    
    });
    
    评论

报告相同问题?