doulianxing4015 2011-11-04 08:18
浏览 15
已采纳

从PHP自动提出

I have a php file that reads data from my mysqldb as a json array. The data should be displayed if the user types in 3 characters.

JS:

<link rel="stylesheet" href="js/demos.css"> //JQuery AutoSuggest Css
    <script>
    $(function() {
        var availableTags = <?php include("/php/getAllRecipes.php"); ?>;


        $( "#searchrecipes" ).autocomplete({
            source: availableTags
        });
    });
    </script>
        <input id="searchrecipes" type="text" name="searchrecipes" class="searchinput" style="margin-left: 850px; margin-top: 0px; width:170px; background: #fff url(images/search_icon.png) no-repeat 100%;" placeholder="Suchen..."></input>
        <input type="submit"1 name="buttonsenden" style="display:none;" value="" width: 5px></input>

Problem:

We have to get the data into the array in our JS calles "availableTags".

  • 写回答

1条回答 默认 最新

  • dongmu6578 2011-11-04 08:21
    关注
    var availableTags = JSON.parse(<?php include("/php/getAllRecipes.php"); ?>);
    

    That is assuming that your PHP file outputs valid JSON, WITH surrounding quotes.
    Such as: echo '"'.addslashes(json_encode($data)).'"';

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据