duandingqi9442 2016-04-29 08:44
浏览 8

使用Ajax生成选择框

My AJAX works fine but when I want to populate Select box, I get nothing displayed:

My HTML:

<div id="sim-div"></div>

My JS:

$(document).on('change', '#hotspotList', function(){
    var selectedHotspots = $('#hotspotList').val();
    $.ajax({ 
        url: "simList.php",
        type: "POST",
        dataType:"json", //expect json value from server
        data: selectedHotspots
    }).done(function(data){ //on Ajax success
        $("#sim-div").html(data.items);
    })
    e.preventDefault();
});

My PHP:

$test = '
<select  id="hotspotList" class="selectpicker"   data-actions-box="true" data-live-search="true" multiple>
<option>test</option>
</select>
';
echo json_encode(array('items'=>$test));

When I change $test= 'something'; it works and I get the word 'something' displayed.

When I log , console.log(data.items); and I get :

<select id="hotspotList" class="selectpicker" data-actions-box="true" data-live-search="true" multiple> <option>test</option> 
</select> 

But when I delete the options of select (id="hotspotList" class="selectpicker" data-actions-box="true" data-live-search="true" ), it works, seems like the problem in the cotes, but I need them

  • 写回答

3条回答 默认 最新

  • doupian9490 2016-04-29 09:01
    关注
    $(document).on('change', '#hotspotList', function(){
        var selectedHotspots = $('#hotspotList').val();
        $.ajax({ 
            url: "simList.php",
            type: "POST",           
            data: selectedHotspots,
            success:function(data){
                  $("#sim-div").html($.parseHTML(data));
            }
        });
    });
    

    My php :

    echo $test = '<select  id="hotspotList" class="selectpicker"   data-actions-box="true" data-live-search="true" multiple>
    <option>test</option>
    </select>
    ';
    

    hope it will help..

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?