dongnuo4594 2015-06-11 16:46
浏览 24

如何使用动态数组调用ajax中的数据

I need to call some data after clicking on an <option name="xxx"> in a <select> in index.php.

The data that I need to call are stored in some dynamic arrays in a different page (select.php)

I have created some arrays in this way in select.php page

${$team} = array();

The string contained in $team that names the array is exactly the value and the name of each of my select options.

So for instance I have<option value="jack">jack</option> in index.php and I have in select.php:

$team = "jack";
${$team} = ("name1", "name2", "name3");

(of course my explanation is simplified or I would create directly the $jack = array(); :-)!

I tried in this way but it doesn't seem to work:

index.php

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script type="text/javascript">
        function fillSelect(){
            var $select = $('#sub_category'); 
            $select.find('option').remove(); 
            if($('#root_category').val() != '#'){
                $.getJSON( 'select.php', {
                    root_category: $('#root_category').val()
                    }
                )
                .done(function( data ) {
                    $.each( data, function( key, value ) {
                        $('<option>').val(key).text(value).appendTo($select);
                    });
                });
            }
        }
    </script>
<form name="module" id="idModule" method="post" action="action.php">
     Chose team:
        <select name="root_category" id="root_category" onChange="fillSelect();">
            <option value="#">Selezionare</option>
            <option value="jack">jack</option></select>

        Here I want to show results<select name="sub_category" id="sub_category"></select>
    </form>

and in select.php

json_encode(${$_GET['root_category']});
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大