Javascript 在传单中通过AJAX更新弹出窗口的内容

Javascript 在传单中通过AJAX更新弹出窗口的内容,javascript,ajax,dom,popup,leaflet,Javascript,Ajax,Dom,Popup,Leaflet,我正在尝试更新传单中弹出窗口的内容。首先,我创建标记并将弹出窗口绑定到它们: $.ajax({ type: "GET", url: "/?p=map&json=1"+filter, dataType: 'json', success: function (response) { geojson = L.geoJson(re

我正在尝试更新传单中弹出窗口的内容。首先,我创建标记并将弹出窗口绑定到它们:

$.ajax({
                type: "GET",
                url: "/?p=map&json=1"+filter,
                dataType: 'json',
                success: function (response) {
                    geojson = L.geoJson(response, {
                        pointToLayer: function (feature, latlng) {
                            return L.marker(latlng); 
                        },
                        onEachFeature: onEachFeature
                    });
                    markers.addLayer(geojson);
                    map.addLayer(markers);
                    });
                }
            });
var layers = [];
function onEachFeature(feature, layer) {
            feature.layer = layer;
            layer.origID = feature.properties.id;

            if (feature.properties && feature.properties.project_name) {
                var divNode = document.createElement('DIV');
                divNode.innerHTML = 'initial popup content from database <button onclick="makeAjaxCall('+feature.properties.id+')">more</button>'; 
                layer.bindPopup(divNode);
            }

            layers.push(layer);

        }
$.ajax({
键入:“获取”,
url:“/?p=map&json=1”+过滤器,
数据类型:“json”,
成功:功能(响应){
geojson=L.geojson(响应{
pointToLayer:功能(特性、latlng){
返回L.标记(板条);
},
onEachFeature:onEachFeature
});
markers.addLayer(geojson);
添加图层(标记);
});
}
});
var层=[];
功能onEachFeature(功能,图层){
feature.layer=图层;
layer.origID=feature.properties.id;
if(feature.properties&&feature.properties.project\u name){
var divNode=document.createElement('DIV');
divNode.innerHTML='数据库中的初始弹出内容更多';
层绑定弹出窗口(divNode);
}
层。推(层);
}
最初,在弹出窗口中有一个按钮,它会触发对更新的弹出内容的ajax调用

该ajax调用返回并调用setPopupContent():

函数setPopupContent(id,数据){

对于(var i=0;i您的弹出窗口宽度受
L.popup
maxWidth
选项约束,该选项默认为300px:

在绑定/初始化弹出窗口时,可以轻松设置此选项,如下所示:

L.Marker([0, 0]).bindPopup('Lorem', {maxWidth: 600}).addTo(map);

Plunker上的叉子:

无法使用传单0.7.7:@iH8重现您的问题试试这个叉子:啊,我明白了。发布了答案。谢谢!您知道将maxWidth设置为100%视口的方法吗?在小屏幕上,提供固定像素值不是最好的方法…您可以使用
L.Map
获取使用ize
方法确定地图的大小,并使用该方法为
L.Popup创建正确的
minWidth
maxWidth
选项
L.Marker([0, 0]).bindPopup('Lorem', {maxWidth: 600}).addTo(map);