Possible Duplicate:
Sending PHP json_encode array to jQuery
I have a little function that searches a database for a name through $.post, and it returns details of users with matching search details. The json is produced in php and looks like so:
Array (
[0] => Array ( [user] => 17 [fn] => blah [ln] => gnaaa [email] => [email protected] )
[1] => Array ( [user] => 18 [fn] => blee [ln] => gnaaa [email] => [email protected] )
[2] => Array ( [user] => 19 [fn] => orange [ln] => gnaaa [email] => [email protected] ) )
Now the javascript pulls the user input data from the html, and posts it to the php script
function searchuser() {
var searchvar = $('#searchbar').html();
$.post("Scripts/search.php", {name: searchvar}, function(data) {
alert("userid: " + data[0][user]);
});
}
So here I am trying to alert the number 17, but nothing seems to be working. I'm guessing I've got something wrong with the syntax, but I can't figure out what the right way is. I am also using jQuery, so I'm guessing there's a neater way to do this but I wanted to try plain javascript first. Thanks in advance
'json'as fourth parameter to$.post.