Welcome Guest, Not a member yet? Register   Sign In
output php array
#1

[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 ?
#2

[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');
#3

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

[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).




Theme © iAndrew 2016 - Forum software by © MyBB