如何用html选择和ajax加载mysql重新加载js

xam8gpfp  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(188)

我的问题:当传单从选择框加载并发送数据到ajax一次运行正常,但另一个改变选择框Map到lefleat不重新加载或加载新的纬度和经度。。。请帮帮我。
index.php我上面的代码:

<script>
        var lat;
        var long;
        $(document).ready(function () {
            $('#lunch1').on('change',function () {
                var city_id=$(this).val();

                if(city_id){
                    $.ajax({
                        type:'POST',
                        url:'city_lat_long_load.php',
                        dataType: "json",
                        data:'city_id='+city_id,
                        success:function (data) {

                            if(data.status == 'ok'){
                                lat=data.result.latitude;
                                long=data.result.longitude;
                                //$("#Latitude").val(lat);
                               // $("#Longitude").val(long);

                                $(function() {
                                    // use below if you want to specify the path for leaflet's images
                                    //L.Icon.Default.imagePath = '@Url.Content("~/Content/img/leaflet")';
                                    var curLocation = [lat, long];

                                    // use below if you have a model
                                    // var curLocation = [@Model.Location.Latitude, @Model.Location.Longitude];

                                    if (curLocation[0] == 0 && curLocation[1] == 0) {
                                        curLocation = [46.288491738996690, 38.081338348906720];
                                    }else{
                                       // map.destroy();

                                        //map = L.map('MapLocation').setView(curLocation, 12);
                                    }
                                    var map = L.map('MapLocation').setView(curLocation, 11);

                                    L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
                                        attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                                    }).addTo(map);

                                    map.attributionControl.setPrefix(false);

                                    var marker = new L.marker(curLocation, {
                                        draggable: 'true'
                                    });

                                    marker.on('dragend', function(event) {
                                        var position = marker.getLatLng();
                                        marker.setLatLng(position, {
                                            draggable: 'true'
                                        }).bindPopup(position).update();
                                        $("#Latitude").val(position.lat);
                                        $("#Longitude").val(position.lng).keyup();

                                    });

                                    $("#Latitude, #Longitude").change(function() {
                                        var position = [parseInt($("#Latitude").val()), parseInt($("#Longitude").val())];
                                        marker.setLatLng(position, {
                                            draggable: 'true'
                                        }).bindPopup(position).update();
                                        map.panTo(position);

                                    });

                                    map.addLayer(marker);
                                    map.release();
                                });

                            }
                        }
                    });
                }
            });
        });

    </script>

问题:何时更改 lunch1 选择框首先更改工作,但另一个更改Map未加载。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题