如何获得ajax响应值?

时间:2015-04-28 10:23:19

标签: php jquery

这是我的查询,

的index.php

$('#users').focusin(function(){
var zid=$('#zoneid').val();
$.post('search.php',{zid:zid},function(data)
{
var availableTags = [data];
        $("#users").autocomplete({
            source: availableTags
        });
});
});

和 的search.php

<?php
require_once('config.php');
$zqry='';
if(isset($_POST['zid']))
{

$zqry=" AND `zone_id`='".$_POST['zid']."'";
}
$query  = "SELECT * FROM `customers` WHERE delete='0' $zqry ";
        $result = Query($query);
        while ($row = $result->fetch_assoc())
        {   
        $store_name .=realEscapeStr($row['store_url']).' #'.$row['access_id'].',';
        }
        $name=substr($name,0,strlen($name)-1);
        echo $name=str_replace("http://","",$name); 
?>

我得到这样的结果,

127.0.0.1/my-build/ #83316859,127.0.0.1/my-build/ #12910708,127.0.0.1/my-build/ #92626735,127.0.0.1/my-build/ #27587635,127.0.0.1/my-build/ #47499649,127.0.0.1/my-build/ #67100051,127.0.0.1/my-build/ #47298211

但我想这样

127.0.0.1/my-build/ #83316859
127.0.0.1/my-build/ #12910708
127.0.0.1/my-build/ #92626735

如何在自动完成框中得到这样的结果?

由于

1 个答案:

答案 0 :(得分:0)

我猜这两条评论(Satpal和jroen)都能胜任

以下是您的代码的样子:

<?php
require_once('config.php');
$zqry='';
if(isset($_POST['zid']))
{

$zqry=" AND `zone_id`='".$_POST['zid']."'";
}

$returnThis = array();
$query  = "SELECT * FROM `customers` WHERE delete='0' $zqry ";
        $result = Query($query);
        while ($row = $result->fetch_assoc())
        {   
            $name .='"'. realEscapeStr($row['url']).' #'.$row['access_id'].'",';
            $name=substr($name,0,strlen($name)-1);
            $name=str_replace("http://","",$name);
            $returnThis[] = $name;
        }
        var_dump($returnThis);
?>

注意$returnThis变量