How to get ajax response value?

This is my request,

index.php

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

      

and 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); 
?>

      

I am getting a result like this,

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

      

but i want like this

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

      

How to do it in an automatic box?

thank

+3


source to share


1 answer


I think both comments (Satpal and jroen) can do the job

This is how it will look for your code:



<?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);
?>

      

Pay attention to the variable $returnThis

0


source







All Articles