unemployment Posted June 7, 2011 Share Posted June 7, 2011 In my php ajax script I have... foreach ($data[0] as $k => $r) { if (($r['feedid'] != $user_info['uid']) && (!empty($r['action_id'])) && ($r['accounttyperaw'] !== '') && ($r['action_id'] != 'joinedcompany') && ($r['action_id'] != 'companyprofilepicture')) { $data[0]['s_u_avatar'] = "/assets/img/avatars/defaultuser.jpg"; } else if (($r['accounttyperaw'] == '') || ($r['action_id'] == 'joinedcompany') || ($r['action_id'] == 'companyprofilepicture')) { $data[0]['c_avatar'] = "/assets/img/avatars/defaultcompany.jpg"; } else { $data[0]['f_u_avatar'] = "/assets/img/avatars/defaultuser.jpg"; } } That returns this... <pre>Array ( [0] => Array ( [id] => 1 [firstname] => gdd [lastname] => Biogdgddgndo [username] => dgd [industry] => [stage] => [companyid] => [companytag] => [gender] => 0 [accounttyperaw] => 1 [accounttype] => dgg [country] => 231 [state] => 10 [city] => Old Lyme [approveddate] => 1307226996 [feedid] => 4 [feedfirstname] => fgd [feedlastname] => fdg [feedusername] => vfgbd [action_id] => usergoal [details] => ckvzokvozk [display_name] => Jason [associate_name] => Chefgdgdgdlsea [f_u_avatar] => /assets/idmg/afgdgdvatars/usdgdgdgfers/jasonbigdgondo.png [s_u_avatar] => /asdgdggdggsets/img/ggddgavatars/users/lovebug.png [c_avatar] => /assgdgdg ) [1] => Array ( [id] => 1 [firstname] => Jdgadgdggdgdgdson [lastname] => Biogdgdgdgndo [username] => gd [industry] => [stage] => [companyid] => [companytag] => [gender] => 0 [accounttyperaw] => 1 [accounttype] => gd [country] => 231 [state] => 10 [city] => Old gdg [approveddate] => 1307226988 [feedid] => 4 [feedfirstname] => dg [feedlastname] => Madgdngs [feedusername] => dg [action_id] => usergoal [details] => dofkasokf [display_name] => Jason dg [associate_name] => Chfgd [f_u_avatar] => gdg [s_u_avatar] => bbfd [c_avatar] => ) ) ajax.get('/assets/ajax/home_news_feed.php?uid=' + uid, function (resp) { var feed = eval('(' + resp + ')'); for(var i = 0; i < feed.length; i++) { stuff } } fut my feed.length isn't working at all. I don't think my array is correct. Link to comment https://forums.phpfreaks.com/topic/238607-php-ajax-javascript-array-structure-fails/ Share on other sites More sharing options...
fugix Posted June 7, 2011 Share Posted June 7, 2011 what are you passing through your function Link to comment https://forums.phpfreaks.com/topic/238607-php-ajax-javascript-array-structure-fails/#findComment-1226212 Share on other sites More sharing options...
unemployment Posted June 7, 2011 Author Share Posted June 7, 2011 what are you passing through your function I'm passing through the array in the pre Link to comment https://forums.phpfreaks.com/topic/238607-php-ajax-javascript-array-structure-fails/#findComment-1226227 Share on other sites More sharing options...
kenrbnsn Posted June 7, 2011 Share Posted June 7, 2011 I find that when using AJAX with PHP, it is much easier to pass arrays from PHP back to Javascript if I use the JSON format. Since it looks like you're using the jQuery library, I would suggest you look at $.post or $.get as a simpler way of doing the AJAX code. Ken Link to comment https://forums.phpfreaks.com/topic/238607-php-ajax-javascript-array-structure-fails/#findComment-1226229 Share on other sites More sharing options...
fugix Posted June 7, 2011 Share Posted June 7, 2011 also, eval() parameter accepts strings....not arrays Link to comment https://forums.phpfreaks.com/topic/238607-php-ajax-javascript-array-structure-fails/#findComment-1226230 Share on other sites More sharing options...
unemployment Posted June 7, 2011 Author Share Posted June 7, 2011 I find that when using AJAX with PHP, it is much easier to pass arrays from PHP back to Javascript if I use the JSON format. Since it looks like you're using the jQuery library, I would suggest you look at $.post or $.get as a simpler way of doing the AJAX code. Ken Hi Ken, I'm not using JQuery and I am encoding the array in json. When I run feed.length my array is only equal to 1, but I know that there should be more rows listed as the json encoded array includes them. Link to comment https://forums.phpfreaks.com/topic/238607-php-ajax-javascript-array-structure-fails/#findComment-1226231 Share on other sites More sharing options...
unemployment Posted June 7, 2011 Author Share Posted June 7, 2011 also, eval() parameter accepts strings....not arrays I do encode this in json which works in my other ajax calls. Link to comment https://forums.phpfreaks.com/topic/238607-php-ajax-javascript-array-structure-fails/#findComment-1226232 Share on other sites More sharing options...
kenrbnsn Posted June 7, 2011 Share Posted June 7, 2011 You probably should do some debugging using Firebug & Firefox to see what you're actually passing back to the Javascript. Ken Link to comment https://forums.phpfreaks.com/topic/238607-php-ajax-javascript-array-structure-fails/#findComment-1226233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.