2016-02-05 08:06


I have developed following code which getting data from db.

    //get number of stores for zip code 
    $numberofstores = $resultstore = mysqli_query($conn, "SELECT store,address FROM geoinfo WHERE zipcode = '$search_text'");  
    //get values from db 

    $addressArray = Array();
    $storeArray = Array();

    while ($row = mysqli_fetch_array($resultstore, MYSQL_ASSOC)) {
    $storeArray[] =  $row['store'];  
    $addressArray[] = $row['address']; 
    //return data to the client 
    echo json_encode($addressArray); 
    echo json_encode($storeArray); 

  $total =  mysqli_num_rows($resultstore);
    if(mysqli_num_rows($resultstore) != 0) {
    echo "".$total." store/s found within this area";    

Here is my ajax call ,

  $(function () {

 $('#form_geocode').on('submit', function (e) {

            type: 'post',
            url: 'controller.php',
            dataType: 'text',
            data: $('#form_geocode').serialize(),
            success: function (data) { 
          for (var x = 0; x < data.length; x++) { 






On success output is,

["226 N LARCHMONT BLVD, LOS ANGELES, CA","670 S WERN AVE, LOS ANGELES, CA","3201 W 6TH ST, LOS ANGELES, CA"]["RITE AID PHARMACY","RALPHS","WALGREENS?"]3 store/s found within this area      

My question is how can I extract 2 arrays into 2 arrays in js and store text separate variable.Please help.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongshungou7699 dongshungou7699 5年前

    Simple, combine the 3 elements into a larger array before JSON encoding;


    echo json_encode($addressArray); 
    echo json_encode($storeArray); 
    echo "".$total." store/s found within this area"; 


    echo json_encode(array($addressArray, $storeArray, "".$total." store/s found within this area"));    
    点赞 评论 复制链接分享