【发布时间】:2016-10-22 11:31:52
【问题描述】:
我有一个 Ajax 函数 (ajaxRequest),我想在特定时间(比如 5 秒)后自动运行,而不需要任何用户提示或警告。我怎样才能做到这一点? (我查看了以下链接,但没有找到解决方案)
jQuery: How to make an AJAX request and continue without waiting for request to complete?
How do I run ajax request in background continuously?
How to run ajax call in background after some particulate time?
How to run execute page in background using ajax?
//My Code
//ajaxRequest Script..
<script type="text/javascript">
function ajaxRequest(map){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", 'json_data.php', true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var myArr = JSON.parse(xmlhttp.responseText);
setMarkers(map,myArr);
}
};
xmlhttp.send(null);
}
</script>
<script>
function myMap() {
var mapCanvas = document.getElementById("map");
var myCenter = new google.maps.LatLng(51.508742,-0.120850);
var lat=51.508742;
var lng=-0.140850;
var mapOptions = {center: myCenter, zoom: 5};
var map = new google.maps.Map(mapCanvas,mapOptions);
ajaxRequest(map); //Called ajaxRequest
}
</script>
【问题讨论】:
-
谷歌 setTimeout()
标签: javascript php ajax