在ajax中返回多个数据 - php

我正在用php开发一个类似facebook的社交网站。我在名为showdetails.php的页面中有一个搜索栏,当用户在搜索框中键入字母时,该页面应在dropdown list like div which can be clicked for selection中显示用户名(数据库中)。我已经使用ajax完成了此操作。我在下拉列表中单击一个特定的用户名,它自动出现在搜索框中。我的问题是还有一个div需要显示该用户单击的所选用户的详细信息。我已经搜索了很多但无法获取正确的。我不知道从ajax调用返回两个不同的值,因为据我所知,var response = xmlhttp.responseText;变量响应只能存储一个结果。

我的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;

我在showdetails.php中的javascript函数

   function showVal(val)
{
    document.getElementById("quicksearch").value=val;
    document.getElementById("search").style.display="none";
}

参考方案

//服务器端:

$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);
    }
});

PHP:将数组值加在一起 - php

我相信这比标题听起来要难一些,但我可能完全错了。我有一个像这样的数组:[["londrina",15],["cascavel",34],["londrina",23],['tiradentes',34],['tiradentes',21]] 我希望能够采用通用…

PHP JQuery复选框 - php

我有以下片段。 var myData = { video: $("input[name='video[]']:checked").serialize(), sinopse: $("#sinopse").val(), dia: $("#dia").val(), quem: $(&#…

如何从php中获取datatables jQuery插件的json数据 - php

我是PHP的新手,正在尝试使用Datatables jQuery插件。我知道我必须从.php文件中获取数据,然后在数据表中使用它,但是我似乎无法通过ajax将其传递给数据表。我设法从数据库中获取数据,并对其进行json编码,但是后来我不知道如何在我的index.php文件中调用它,并在其中显示它。我究竟做错了什么?这是我的代码:HTML(已编辑): <…

PHP strtotime困境 - php

有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00�…

PHP-全局变量的性能和内存问题 - php

假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…