CodeIgniter Forums
output php array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: output php array (/showthread.php?tid=35295)



output php array - El Forum - 10-25-2010

[eluser]Fireclave[/eluser]
hi, i'm using php and jquery to show files with ajax.

the server is sending a

echo "hi"

but my foreach with

foreach(..)
echo '..';

is not working. but this works WITHOUT jquery.
Is it possible, that the outputted datas are toooo big ?

This are 100 Rows with 7 Columns, so this is is not so small Undecided

Have anyone ideas ?

Is there a way to convert a php array to javascript array ?


output php array - El Forum - 10-25-2010

[eluser]LuckyFella73[/eluser]
Better try to send response from your controller using json.

Depending how your array entries are named, print out the
returned data. In case your array would look like:
Code:
$array = array ('message' => 'everything is fine');
echo json_encode($array);

Code:
// your view file:
$.post("<?php echo base_url(); ?>your_controller", {"your_value" : value},
function(data)
{
    var msg = data.message;
    alert(msg); // to check if values are returned
}, 'json');



output php array - El Forum - 10-26-2010

[eluser]Fireclave[/eluser]
thx i will try this. How does it woks with multidimensional arrays ?


output php array - El Forum - 10-26-2010

[eluser]WanWizard[/eluser]
The same as with any other value.

Note that json_encode is PHP 5.2+. If you use an other version, you could use my helper. You need both the ajax helper and JSON.php (which contains the json_encode/json_decode logic).