dongxia9620 2014-01-02 01:46
浏览 465
已采纳

如何在json中获取第二个数组?

I have use auto complete with json and php. it works, but now I need to get the second array from the json.

This my script on source.php

<?php

$req = "SELECT namaBarang, harga FROM masternamabarang WHERE namaBarang LIKE '%".$_REQUEST['term']."%' ";

       $query = mysql_query($req);

       while($row = mysql_fetch_array($query))
       {
           $results[] = array('label' => $row['namaBarang'],'harga' => $row['harga']);
       }

       echo json_encode($results);  
?>

and this script for autocomplate.php

<html>
   <head>

    <script src="js/jquery-1.9.1.js"></script>
    <script src="json/js/jquery-ui-1.10.3.js"></script>
    <script>
      $(function() 
      {
       $( "#NAMA" ).autocomplete({
           source: 'source.php'
      });
      });
    </script>

    <script>
    function ambil()
    {
    var x = document.getElementById('NAMA').value;

    document.getElementById('HARGA').value=x;   
    }
    </script>
</head>
<body>
  <form>
    <input type="text" name="NAMA" size="50" id="NAMA" onchange="ambil()"/><br>
    <input type="text" name="HARGA"  size="50"  id="HARGA" />

  </form>
</body>

The Autocomplete works well, but ALL I need is, take the second array[HARGA] from JSON array and fill it on text box HARGA.

I appreciate your answers.

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 postman测试正常,在代码运行报错
      • ¥15 关于#C语言#的问题,如何解决?
      • ¥20 Vs2017 Help Viewer2.3 问题
      • ¥35 基于嵌入式linux的日程管理软件
      • ¥50 如何将list字符串添加到CSV文件表头?
      • ¥15 关于#javascript#的问题:通过ajax实现的局部刷新 如何将项目打包
      • ¥15 海思uboot USB3.0无法识别
      • ¥15 无法调用库文件,自己可以找到,但编译时显示没有
      • ¥15 安装PyQt5的时候这里创建虚拟环境是哪里?具体是怎么的?能录个视频吗
      • ¥20 php程序设计题不会!求解答!