【发布时间】:2016-10-14 10:14:18
【问题描述】:
我目前正在处理一个项目,但不知道如何刷新 AJAX 请求。 目前我的代码工作正常,我可以显示所有标记,但我想每 5 秒刷新一次并接收新的! 在我的脚本副本下面,我尝试使用 setInterval 没有成功喷射! 这方面的帮助将非常棒。 再次感谢。
var gMapsLoaded = false;
window.gMapsCallback = function(){
gMapsLoaded = true;
$(window).trigger('gMapsLoaded');
}
window.loadGoogleMaps = function(){
if(gMapsLoaded) return window.gMapsCallback();
var script_tag = document.createElement('script');
script_tag.setAttribute("type","text/javascript");
script_tag.setAttribute("src","http://maps.google.com/maps/api/js?sensor=false&callback=gMapsCallback");
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
}
$(document).ready(function(){
function initialize(){
var mapOptions = {
zoom: 18,
center: new google.maps.LatLng(51.5207239719, -0.182568696184),
mapTypeId: google.maps.MapTypeId.ROADMAP};
map = new google.maps.Map(document.getElementById('map_canvas'),mapOptions);
}
$(window).bind('gMapsLoaded', initialize);
window.loadGoogleMaps();
});
$(window).load(function update () {
$.ajax({
url: 'get-last.php',
success:function(data){
//Loop through each location.
$.each(data, function(){
//Plot the location as a marker
var pos = new google.maps.LatLng(this.latitude, this.longitude);
new google.maps.Marker({
position: pos,
map: map
});
});
} , complete: function() {
setInterval(update, 1000);
}
});
【问题讨论】:
标签: javascript jquery ajax refresh