0

下面是我想使用 jquery 的每个函数在 ajax-jquery 中处理的多维数值数组。我正在尝试使用 parseJSON 进行处理,但在警报结果中始终显示未定义。所以我没有编码这个数组以在 jquery 中处理。任何帮助都会得到帮助。提前致谢。

Array
  (
   [0] => Array
    (
        [image_mapid] => 22
        [image_id] => 2
        [user_id] => 1228143758
        [pos_x] => 602.5333251953125
        [pos_y] => 300.3333282470703
        [image_width] => 100
        [image_height] => 100
    )

[1] => Array
    (
        [image_mapid] => 25
        [image_id] => 2
        [user_id] => 1326497290
        [pos_x] => 446.5333251953125
        [pos_y] => 250.3333282470703
        [image_width] => 100
        [image_height] => 100
    )

[2] => Array
    (
        [image_mapid] => 26
        [image_id] => 2
        [user_id] => 1757521573
        [pos_x] => 154
        [pos_y] => 162
        [image_width] => 204
        [image_height] => 190
    )
)

 var tag_select = '<?php echo $basepath?>Userprofile/tagselect.php';

 jQuery.ajax({  
                type: 'GET',
                url: tag_select,
                dataType:'json',
                data: 'wallid='+wid+'&userid='+<?php echo $user_id;?>,

                Success: function(data) {
                   $.each(data, function(idx, obj){
                     console.log(obj.image_mapid, obj.image_id)
                                             })
                                    }

               });
4

2 回答 2

2

据我所知,数据是一个对象数组,所以试试

$.each(data, function(idx, obj){
    console.log(obj.image_mapid, obj.image_id)
})
于 2013-06-19T07:03:04.003 回答
1

首先dataType:'json'从 AJAX 中删除并尝试一下。

并且如果你提供了 Json 解析源,这将有助于找到实际的问题。

只需像下面这样给出 Ajax,

 jQuery.ajax({  
                'type': 'GET',
                'url': tag_select,
                'data': 'wallid='+wid+'&userid='+<?php echo $user_id;?>,

                'success': function(data) {
                    // process the array here
                                    }

               });
于 2013-06-19T07:29:19.390 回答