Php 在ajax中返回多个数据

Php 在ajax中返回多个数据,php,jquery,ajax,Php,Jquery,Ajax,我正在用php开发一个类似facebook的社交网站。我在一个名为showdetails.php的页面中有一个搜索栏,当用户在搜索框中键入字母时,该搜索栏应该会在下拉列表(如div)中显示用户的姓名(在数据库中)。当我在下拉列表中单击特定用户名时,它会自动进入搜索框。我的问题是,还有一个div需要显示用户单击的所选用户的详细信息。我搜索了很多,但没有找到正确的。我不知道从ajax调用返回两个不同的值,因为据我所知,var response=xmlhttp.responseText,变量响应只能存

我正在用php开发一个类似facebook的社交网站。我在一个名为
showdetails.php
的页面中有一个搜索栏,当用户在搜索框中键入字母时,该搜索栏应该会在
下拉列表(如div)中显示用户的姓名(在数据库中)。当我在下拉列表中单击特定用户名时,它会自动进入搜索框。我的问题是,还有一个div需要显示用户单击的所选用户的详细信息。我搜索了很多,但没有找到正确的。我不知道从ajax调用返回两个不同的值,因为据我所知,
var response=xmlhttp.responseText,变量响应只能存储一个结果

My
searchvalues.php
,其中包含搜索用户名的代码

       $hint = "<table>";
       while($row = mysql_fetch_array($result_query_get_following))
     {
         $act_fname = $row['acnt_fname'];
         $act_lname = $row['acnt_lname'];
         $act_name = $act_fname . ' ' . $act_lname;
         $hint.= "<tr onClick='showVal(\"".$act_name."\");'><td >".$act_name."</td></tr>";
         $following_id = $row['flwing_following_user_id'];
         $following_member_class = $row['acnt_member_class'];
         $following_profile_picture = $row['acnt_profile_picture'];
    }
     $hint .= "</table>";
}
  if ($hint == "")
  {
$response="no suggestion";
   }
 else
 {
$response=$hint;
 }

//output the response
echo $response;

据我所知,从一个函数返回两个元素是不可能的。您可以做的是创建一个元素数组并返回该特定数组

假设这是PHP,因为您没有提供任何代码

其他的 您可以尝试返回数据


据我所知,从函数返回两个元素是不可能的。您可以做的是创建一个元素数组并返回该特定数组

假设这是PHP,因为您没有提供任何代码

其他的 您可以尝试返回数据

//服务器端:

$return_data['status'] = '0';

$return_data['msg'] = 'Your message.'; 

echo json_encode($return_data);exit;
//客户端

$.ajax({
    dataType: "json",
    type: "POST",
    url: 'Your url',
    data: ({parm1:value1,...}),
    success: function (data, textStatus){
        $("#div1").html(data.msg);
        $("#input1").val(data.status);
    }
});
//服务器端:

$return_data['status'] = '0';

$return_data['msg'] = 'Your message.'; 

echo json_encode($return_data);exit;
//客户端

$.ajax({
    dataType: "json",
    type: "POST",
    url: 'Your url',
    data: ({parm1:value1,...}),
    success: function (data, textStatus){
        $("#div1").html(data.msg);
        $("#input1").val(data.status);
    }
});

$(“#单击了用户”)。单击(函数(){
var q=document.getElementById('clicked_user')。值;
var loadUrl=“getuserinformation.php?query=q”;
美元邮政
(
loadUrl,{语言:“php”,版本:5},函数(responseText){$(“#user_detail”).html(responseText);},“html”
);
})
getuserinformation.php中,通过$\u get获取查询参数,在此处执行查询并回显希望显示在div中的信息


$(“#单击了用户”)。单击(函数(){
var q=document.getElementById('clicked_user')。值;
var loadUrl=“getuserinformation.php?query=q”;
美元邮政
(
loadUrl,{语言:“php”,版本:5},函数(responseText){$(“#user_detail”).html(responseText);},“html”
);
})

getuserinformation.php中,通过$\u get获取查询参数,在此处执行查询并回显希望显示在div中的信息

@NullPointer我不知道jsoncreate json在php中,而不是返回(回显)json。。并通过jquery中的each()获取内容success@NullPointer我不知道JSONCreateJSON在php中,而不是返回(echo)json。。并通过jquery success中的each()获取内容
<div id="user_detail"></div>

    <script>
    $("#clicked_user").click(function(){
        var q =  document.getElementById('clicked_user').value;
        var loadUrl = "getuserinformation.php?query=q";
        $.post
        (
          loadUrl,{language: "php", version: 5},function(responseText){$("#user_detail").html(responseText);},"html"
        );
    })
    </script>