[問題] json 回傳多個值
我想從資料庫撈資料(多筆)放回頁面
無奈小弟不會用json 得到的都是object Object
懇請各位前輩賜教 或是提供關鍵字 ~"~
以下是用jQuery autocomplete改的
http://jqueryui.com/autocomplete/#remote
----------search.php----------
$stmt = $conn->prepare('select id,name from table');
$stmt->execute();
while($row = $stmt->fetch()) {
$return_arr[] = $row;
}
echo json_encode($return_arr);
------------------------------
會得到多行
example:
[{"id":455,"0":455,"name":"\u6c5f","1":"\u6c5f"},
{"id":393,"0":393,"name":"\u8521","1":"\u8521"}]
----------jQuery----------
$( "#birds" ).autocomplete({
source: "search.php",
minLength: 2,
response: function( event, ui ) {
log( ui );
}
});
function log( message ) {
$( "<div>" ).text( messageitem.value ).prependTo( "#output" );
$( "#output" ).scrollTop( 0 );
}
----------html----------
<div>
<label for="birds">Birds: </label>
<input id="birds" />
</div>
<div>
<div id="output"> Here </div>
</div>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.81.228.254
※ 編輯: cold514 來自: 219.81.228.254 (05/31 18:26)
推
05/31 20:22, , 1F
05/31 20:22, 1F
→
05/31 20:52, , 2F
05/31 20:52, 2F
→
05/31 20:53, , 3F
05/31 20:53, 3F
→
05/31 20:54, , 4F
05/31 20:54, 4F
→
05/31 20:54, , 5F
05/31 20:54, 5F
→
05/31 20:54, , 6F
05/31 20:54, 6F
→
05/31 20:56, , 7F
05/31 20:56, 7F
→
05/31 20:56, , 8F
05/31 20:56, 8F
→
05/31 20:56, , 9F
05/31 20:56, 9F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章