如何通过jquery $ .ajax函数从php脚本中理解和检索多个值?

While using jquery $.ajax or $.post, to submit a value (say uid {user id}) how can I define a callback function to retrieve multiple values from the php script and retrieve values from my mysql table say(user details, corresponding to the uid) and store them in vars, using the default datatype:datatype???

Can anyone please show me both the jquery and php scripts please. And yes the database is runninga mySQL 5.5.24 and PHP version is 5.3

instead of using $.ajax you can also use this...

var id=$("#id").val();
 $.getJSON('script.php', {id:id}, function(json) {
                        var id=json.id;
                        var name=json.name;
                        var email=json.email;

        });
            }


in your php scrip..    
<?php 
    mysql_connect($host,$dbuser,$dbpass);
    mysql_select_db($db_name);
    $id=$_GET['id'];
    $query="select * from tbl_name where id='$id'";
    $rs=mysql_query($query);
    $row=mysql_fetch_assoc($rs);
    $id=$row['id'];
    $name=$row['name'];
    $email=$row['email'];
    $data=array("id"=>$id,"name"=>$name,"email"=>$email);
    echo json_encode($data);
    ?>

The best way to do this would be to send it back to javascript as a json object.... so for your user example

 // assuming post containing a username, using pseudo code for db access

$row = $db->fetchAssoc("select * from users where username = '".dbEscape($_POST["username"]."'");
header("Content Type: application/json");
echo json_encode($row);

ajax code will be like follows

$.ajax({
 type: "POST",
 url: "your_page.php",
 data: { param1: "val1", param2: "val2" }
 }).done(function( data) {
        // do your callback operation
});

get values from your_page.php like below

$_POST["param1"] , $_POST["param2"]

if you want to know more then click here

I think this will solve your problem.

<script type="text/javascript">
$.ajax({ // ajax call starts
          url: 'serverside.php', // JQuery loads serverside.php
          data: 'button=' + $(this).val(), // Send value of the clicked button
          dataType: 'json', // Choosing a JSON datatype
          success: function(data) // Variable data contains the data we get from serverside
          {

          }
      });


</script>
dataType: json..so jason will return multiple values. from you php script 
echo json_encode($array_of_val);
$.ajax({
 type: "POST",
 dataType:"html",
 url: "ajax_page.php",
 data:"params1="$params1"&params2="+$params2,
 }).done(function(value) {
        // write your callback operation
});

you can get your data on ajax_page.php using an post method like

$_POST['params1']; and $_POST['params2'];

$query= select statement
$items=array();
while ($row = mysql_fetch_object($rs)) {
  array_push($items, $row);
}
$result["rows"] = $items;
echo json_encode($result);