Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用ajax-post()从数据库获取Json数据每次都是不同的(变成双精度的) 函数getReady(){ $('.selectpicker').empty();//清除选择项 $.ajax({ 类型:“POST”, contentType:“应用程序/json”, url:“/btlocationServer/GetBeaconInfo”, 数据类型:“json”, cache:false, 成功:功能(数据){ $。每个(数据、功能(i、项){ $('.selectpicker').append(“+item.name+”--“+item.address+”);//将数据追加到select的选项 console.log(item.name+“--”+item.address);//日志数据 }); $('.selectpicker')。selectpicker('refresh')) } }); }_Jquery_Ajax - Fatal编程技术网

Jquery 使用ajax-post()从数据库获取Json数据每次都是不同的(变成双精度的) 函数getReady(){ $('.selectpicker').empty();//清除选择项 $.ajax({ 类型:“POST”, contentType:“应用程序/json”, url:“/btlocationServer/GetBeaconInfo”, 数据类型:“json”, cache:false, 成功:功能(数据){ $。每个(数据、功能(i、项){ $('.selectpicker').append(“+item.name+”--“+item.address+”);//将数据追加到select的选项 console.log(item.name+“--”+item.address);//日志数据 }); $('.selectpicker')。selectpicker('refresh')) } }); }

Jquery 使用ajax-post()从数据库获取Json数据每次都是不同的(变成双精度的) 函数getReady(){ $('.selectpicker').empty();//清除选择项 $.ajax({ 类型:“POST”, contentType:“应用程序/json”, url:“/btlocationServer/GetBeaconInfo”, 数据类型:“json”, cache:false, 成功:功能(数据){ $。每个(数据、功能(i、项){ $('.selectpicker').append(“+item.name+”--“+item.address+”);//将数据追加到select的选项 console.log(item.name+“--”+item.address);//日志数据 }); $('.selectpicker')。selectpicker('refresh')) } }); },jquery,ajax,Jquery,Ajax,这是我第一次启动服务器 第二次刷新页面时: 每次我刷新页面,数据都会翻倍 那么我该如何处理它呢我认为这是因为:$('.selectpicker')。selectpicker('refresh')不是,如果我删除$('.selectpicker')。selectpicker('refresh'),问题仍然存在,选择变得异常 <script type="text/javascript"> function getReady(){ $('.selectpicke

这是我第一次启动服务器

第二次刷新页面时:

每次我刷新页面,数据都会翻倍


那么我该如何处理它呢

我认为这是因为:$('.selectpicker')。selectpicker('refresh')不是,如果我删除$('.selectpicker')。selectpicker('refresh'),问题仍然存在,选择变得异常
<script type="text/javascript">
    function getReady(){
        $('.selectpicker').empty(); //clear the select
            $.ajax({
                type : "POST", 
                contentType : "application/json", 
                url : "/btlocationServer/GetBeaconInfo", 
                dataType : 'json',
                cache:false,
                success : function(data){
                    $.each(data, function(i, item) {
                        $('.selectpicker').append("<option >"+item.name+"--"+item.address+"</option>");   //append data to option of select
                        console.log(item.name+"--"+item.address);//log data
                    });
                    $('.selectpicker').selectpicker('refresh')
                }
            });
    }
</script>