大家好,我遇到了这样的问题,即当ajax在特定时间段内检索仪表板上的数据库数据时。这将引发我一个错误,说localhost:59927未定义。
这是使用ajax的代码。
注意:我已经尝试将时间间隔切换为超时,因为时间间隔会创建一堆ajax请求,而超时仅在特定时间段后才创建一次,但这没有帮助。
var marker1 = [];
var circle = [];
L.Circle.include({
contains: function (latLng)
{
return this.getLatLng().distanceTo(latLng) < this.getRadius();
}
});
$.ajax({
type: "GET",
url: 'http://localhost:59927//api//Values//FlagingDevice(WithoutParameters)',
success: function (data, status, xhr)
{
for (var i = 0; i < data.Table.length; i++)
{
circle[i] = L.circle([data.Table[i].Latitude, data.Table[i].Longitude], 50, { color: '#DA2E2E', opacity: 2, fillColor: 'blue', fillOpacity: .3 }).addTo(map);
}
},
error: function (xhr)
{
alert(xhr.responseText);
}
});
function innerOne()
{
$.ajax({
type: "GET",
url: 'http://localhost:59927//api//Values//FlagingDevice(WithoutParameters)',
success: function (data, status, xhr)
{
for (var s = 0; s < marker1.length; s++)
{
map.removeLayer(marker1[s]);
}
for (var i = 0; i < data.Table.length; i++)
{
var value = i + 1;
if (circle[i].contains(L.latLng([data.Table[i].Latitude, data.Table[i].Longitude])))
{
var customPopup1 = 'Station: ' + data.Table[i].StationName;
var customOptions1 =
{
'maxWidth': '500',
'className': 'custom'
};
circle[i].bindPopup(customPopup1, customOptions1);
setTimeout(function () { innerOne(); }, 30000);
}
else
{
marker1[i] = L.marker([data.Table[i].Latitude, data.Table[i].Longitude]).addTo(map);
var customPopup = 'Latitude: ' + data.Table[i].Latitude + '</br>Longitude: ' + data.Table[i].Longitude
+ '</br>Station: ' + data.Table[i].StationName + ' </br>Box: ' + data.Table[i].Name + '</br>Timestamp: ' + data.Table[i].LocationSend + `<br/><a target='_blank' href='/Home/History?DeviceID=${value}' style='color: #000000'>Click Here For Location History</a><br/>`;
marker1[i].bindPopup(customPopup);
setTimeout(function () { innerOne(); }, 30000);
}
}
},
error: function (xhr)
{
alert(xhr.responseText);
}
});
}