JQuery Autocomplete, populate with data from pHp json

前端 未结 4 658
鱼传尺愫
鱼传尺愫 2021-01-07 09:39

I am returning a JSON encoded array: echo(json_encode($data)); from php and I would like it to populate the suggest box from JQuery autocomplete. I\'m using thi

4条回答
  •  星月不相逢
    2021-01-07 10:43

    the proper json format for this from php:

    
    

    From js wich means []-array of {} objects.

    In my case for autocomlete widjet this works fine:

        $response="[";
        while($row = $res->fetch_assoc()){
            if($response !="[")$response.=",";
            $response.='{"label":"'.$row["fio"].'","value":"'.$row["id"].'"}';
        }
        $response.="]";
    
        echo $response;
    

提交回复
热议问题