dptj13337 2015-07-08 15:12
浏览 34
已采纳

使用ajax更新php选择列表[关闭]

Im New to Ajax and PHP.

I would like to update my php selectlist( which is populated from the file lastlog) using ajax.Im new to ajax and php.Im trying to use onclick javascript action to update my php select list contents from different file

function selectlist()
  {
    $count    = count(file('/var/www/php/userAccount/UserDeactivator/lastlog'));
    $userlist = file('/var/www/php/userAccount/UserDeactivator/lastlog');
    $option   = '';
    $options .= "<option disabled  =CSL>UserID(Total $count Inactive Users)</option>";
    foreach ($userlist as $ong)
      {
        $options .= '<option>' . $ong . '</option>';
      } //$userlist as $ong
    $select = '<select name="Category[]" multiple="multiple"  size="10">' . $options . '</select>';
    // $select = '<select name=''>'.$options.'</select>';
    echo $select;
  }
  • 写回答

1条回答 默认 最新

  • dpikoto468637 2015-07-08 15:39
    关注

    Firstly, your PHP code looks a bit off. You define $option and then append to $options which does not appear to be defined.

    <?php
    function selectlist(){
        $count = count(file('/var/www/php/userAccount/UserDeactivator/lastlog'));
        $userlist = file('/var/www/php/userAccount/UserDeactivator/lastlog');
        $options = '';
        $options .= "<option disabled  =CSL>UserID(Total $count Inactive Users)</option>";
        foreach($userlist as $ong) {
            $options .= '<option>' . $ong . '</option>';
        } //$userlist as $ong
        $select = '<select name="Category[]" multiple="multiple"  size="10">' . $options . '</select>';
        // $select = '<select name=''>'.$options.'</select>';
        echo $select;
    }
    ?>
    

    I think that is what you mean to do. Now I am a fan of JQuery, so I will give you a guess here. Since you did not post any details about your form, it's all my best guess and is untested.

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("#action").click(function(){
            $.get("getSelect.php", function(data){
                $("#dynSelect").html(data);
            });
        });
    });
    </script>
    <a href="#" id="action" class="button">Get Log List</a>
    <div id="dynSelect"></div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化