below is my multi dimensional numeric array that i want to process in ajax-jquery using each function of jquery.i am trying to process using parseJSON but in alert result always displayed undefined. So i am not encode this array to process in jquery. Any help would be appericiated. Thanks in advance.
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)
})
}
});
2 Answers 2
From what I can see the data is an array of objects so try
$.each(data, function(idx, obj){
console.log(obj.image_mapid, obj.image_id)
})
First remove the dataType:'json' from the AJAX and try it.
And if you provide the Json parsing source, it will be useful to find the actual problem.
Just give the Ajax like below,
jQuery.ajax({
'type': 'GET',
'url': tag_select,
'data': 'wallid='+wid+'&userid='+<?php echo $user_id;?>,
'success': function(data) {
// process the array here
}
});
Explore related questions
See similar questions with these tags.