【问题标题】:how to process mutidimensional numeric array using jquery each function如何使用jquery每个函数处理多维数值数组
【发布时间】:2013-06-19 07:00:33
【问题描述】:

下面是我想使用 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)
                                             })
                                    }

               });

【问题讨论】:

    标签: php json jquery multidimensional-array


    【解决方案1】:

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

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

    【讨论】:

    • 我在 console.log 中得到什么我将 javascript 变量分配给 console.log 语句并发出警报,但我什么也没得到......
    • 您好,如果您对此@Arun 有任何了解,请回复
    • 现在我编辑我的问题请检查我的修改@Arun
    【解决方案2】:

    先把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
                                        }
    
                   });
    

    【讨论】:

    • 我在删除 datyTYPE: 'josn' 后尝试了仍然没有成功.. 在警报中它给了我 _firebugingnore...@Akilan
    • 删除 dataType : 'json' 我已经对我的代码进行了任何其他更新,但请帮助我这是紧急的.. @Akilan
    猜你喜欢
    • 1970-01-01
    • 2021-06-09
    • 1970-01-01
    • 2014-09-27
    • 2016-02-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-02
    • 2019-03-13
    相关资源
    最近更新 更多