using a PHP print_r array result in javascript/jquery
Posted
by Phil Jackson
on Stack Overflow
See other posts from Stack Overflow
or by Phil Jackson
Published on 2010-03-27T14:56:31Z
Indexed on
2010/03/27
15:03 UTC
Read the original article
Hit count: 474
Hello all.I have a simple jquery/ajax request to the server which returns the structure and data of an array. I was wondering if there was a quick way in which I can use this array structure and data using jquery;
A simple request;
var token = $("#token").val();
$.ajax({
type: 'POST', url: './', data: 'token=' + token + '&re=8', cache: false, timeout: 5000,
success: function(html){
// do something here with the html var
}
});
the result ( actual result from PHP's print_r(); );
Array
(
[0] => Array
(
[username] => Emmalene
[contents] =>
<ul><li class="name">ACTwebDesigns</li><li class="speech">helllllllo</li></ul>
<ul><li class="name">ACTwebDesigns</li><li class="speech">sds</li></ul>
<ul><li class="name">ACTwebDesigns</li><li class="speech">Sponge</li><li class="speech">dick</li></ul>
<ul><li class="name">ACTwebDesigns</li><li class="speech">arghh</li></ul>
)
)
I was thinking along the lines of
var demo = Array(html); // and then do something with the demo var
Not sure if that would work it just sprang to mind.
Any help is much appreciated.
© Stack Overflow or respective owner