请建议我
var rest = JSONobject[i]["descrizione"];
var descr = rest.substr(0,15);
错误:无法调用 null 的方法“substr”
但“var rest”不是空的。
代码完成:
$.ajax({
type: "GET",
url: "get_info_campotrincerato.php",
success: function (result) {
var JSONobject = JSON.parse(result);
var jnCount = JSONobject.length;
for (var i = 0; i < jnCount; i++) {
var marker = new L.Marker(new L.LatLng(JSONobject[i]["lat"], JSONobject[i]["lng"]),{ icon: myIcon1 });
var rest = JSONobject[i]["descrizione"];
var descr = rest.substr(0,15);
var list = "<dl>"
+ "<dt><b>ID:</b> " + JSONobject[i]["id"] + "</dt>"
+ "<dt>" + descr + "</dt>"
+ "<a href='?id=" + JSONobject[i]["id"] + "'>...go</a>";
marker.bindPopup(list);
marker.on('dblclick', function(e){
marker.openPopup();
});