如何填充点击下拉菜单

时间:2017-09-30 00:28:58

标签: php jquery

我有类别,当我点击下拉列表时,我想用我的下拉列表显示类别。

这种方法确实有效。我需要在代码中更改哪些元素?

谢谢

我的ajax php

    $Qcheck = $OSCOM_Db->prepare('select distinct categories_id as id,
                                                    categories_name as name
                                   from :table_catogories
                                  ');
    $Qcheck->execute();

    $list = $Qcheck->rowCount() ;

    if ($list > 0) {
      $array = [];

      while ($value =  $Qcheck->fetch() ) {
        $array[] = $value;
      }

    # JSON-encode the response
      $json_response = json_encode($array); //Return the JSON Array

    # Return the response
      echo $json_response;

现在是我的档案

        <?php
          $categories_ajax = OSCOM::link('categories_ajax.php');
        ?>

        <script type="text/javascript">
          function myAjax() {
            $("#myAjax").on('click', function(){
              $.ajax({
                url: '<?php echo $categories_ajax; ?>',
                dataType: 'json',
                success: function(data){
                  //data returned from php
                }
              });
            )};
        </script>
// my dropdown
         <?php echo HTML::selectMenu('move_to_category_id', CategoriesAdmin::getCategoryTree(), 'onclick="myAjax()"') . HTML::hiddenField('current_category_id', $current_category_id); ?>

note CategoriesAdmin::getCategoryTree()显示类别名称。它是一个数组

我的下拉功能元素

public static function selectMenu($name, array $values, $default = null, $parameters = '', $required = false, $class = 'form-control') {}

0 个答案:

没有答案