繁体   English   中英

单独的json编码数组结果

[英]Separate json encoded array result

以下php块搜索并返回名称,我想选择一个项目,并且在ajax中能够获取“名称”旁边所选行中的其他项目。 如何用Ajax分开?

<?php
require_once '../php/db_conx.php';
$req = "SELECT name "
    ."FROM profiles "
    ."WHERE name LIKE '%".$_REQUEST['term']."%' "; 
$query = mysql_query($req);
while($row = mysql_fetch_array($query))
{
    $results[] = array('label' => $row['name']);
}
echo json_encode($results);

?>

阿贾克斯

$(function() {
        $( "#SearchInput").autocomplete({
source: 'Search.php',
minLength: 1,
select: function(event, ui) {
$('#Name').append(ui.item.label);
            }
        });
    });

您可以使用_renderItem方法

_renderItem: function( ul, item ) {       
    $( "#selector" ).text( item.name );// let name is in json
}

或者您也可以在选择事件中获得name ,例如

select: function(event, ui) {
   $('#Name').append(ui.item.label);
   $( "#selector" ).text( item.name );// let name is in json
}

尝试这个:

I think you need to parse data from array.

var contact = JSON.parse(jsontext);
document.write(contact.surname + ", " + contact.firstname);

Use the variable name you have used. 
Read More on: http://msdn.microsoft.com/en-us/library/ie/cc836466(v=vs.94).aspx
  • 谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM