හේතුව
setInterval function එකට දෙන්න ඕනෙ පළවෙනි argument එක වෙන්න ඕනෙ callback function එකක්.
setInterval මේ callback function එකට call කරන්නෙ කිසිම argument එකක් නැතුච, ඒ කියන්නෙ
setInterval(downloadUrl,xxxx) ආකාරයට දුන්නම downloadUrl එකේ තියන url, callback කියන parameter දෙකටම ලැබෙන අගය වෙන්නෙ undefined.
https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval
පිලියම
setInterval එකේ පළවෙනි argument එක හැටියට anonymous/lambda function එකක් දෙන්න, ඒක ඇතුලෙ
downloadUrl එකට call කරන්න නිවැරදි argument සමග.
Code:
setInterval(function() {
downloadUrl(yourURLHere, yourCallbackHere)
}, 45000)
anonymous/lambda function පාවිච්චි කරන්න අකමැතිනම් මෙහෙමත් කලහැකි:
Code:
setInterval(downloadUrl, 45000, yourURLHere, yourCallbackHere)
හැබැයි මේ ක්රමය පරණ IE browser (9 and below) support කරන්නෙෙ නෑ.
ගොඩක් ලොකු රිප්ලයි එකක් දාලා නේද මචෝ.. තැන්ක්ස්. ඔන්න උබව රේප් කරා
හරි මම පහලින් මගේ කොඩ් එක පහලින් දාන්නම්. එකට setinterval funtion eka add කරලා දෙන්න. ලොකු උදවුවක් මචෝ මම කොච්චර ට්රයි කරත් හරි යන්නේ නැ. ඇත්තම කතාව මම ජවා ස්කිප්ට් ගැන මෙලෝ හසරක් දන්නේ නැ.. මට මේකේ මැප් එක ලෝඩ් වෙන්නේ නැතිව මකර්ස් ටික විතරක් ලොඩ් කරගන්නයි ඔනි
<!DOCTYPE html >
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>vtrack</title>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var customLabel = {
user: {
label: 'U'
},
bar: {
customer: 'C'
}
};
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(6.716572137030388, 79.95990197875965),
zoom: 12
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP or XML file
downloadUrl('mapmarkers2.php', function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName('marker');
Array.prototype.forEach.call(markers, function(markerElem) {
var name = markerElem.getAttribute('name');
var address = markerElem.getAttribute('address');
var type = markerElem.getAttribute('type');
var point = new google.maps.LatLng(
parseFloat(markerElem.getAttribute('lat')),
parseFloat(markerElem.getAttribute('lng')));
var infowincontent = document.createElement('div');
var strong = document.createElement('strong');
strong.textContent = name
infowincontent.appendChild(strong);
infowincontent.appendChild(document.createElement('br'));
var text = document.createElement('text');
text.textContent = address
infowincontent.appendChild(text);
var icon = customLabel[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
label: type
});
marker.addListener('click', function() {
infoWindow.setContent(infowincontent);
infoWindow.open(map, marker);
});
});
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=&callback=initMap">
</script>
</body>
</html>