मैं निम्न लूप के प्रत्येक पुनरावृत्ति पर 1-2 सेकंड देरी जोड़ना चाहता हूं।जावास्क्रिप्ट लूप को धीमा करने के लिए कैसे करें
<html>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<input id="start" type="submit"> </input>
<div id='status'></div>
<script>
var geocoder=new google.maps.Geocoder();
var glGeocodeCount = 0 ;
$(document).ready(function() {
$('#start').click(function() {
//srPerformGeocode("TD Tower, 55 King Street West, Toronto, ON, Canada, M5K 1A2");
for(x=0;x<20;x++){
srPerformGeocode("TD Tower, 55 King Street West, Toronto, ON, Canada, M5K 1A2");
}
return false;
});
});
function srPerformGeocode(address){
if (geocoder){
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK){
$('#status').prepend("Success : " + address + "<br/>");
}
else{
$('#status').prepend("Failed : " + address + "<br/>");
}
});
}
}
</script>
आप एक ही पते को 20 बार क्यों जियोकोड कर रहे हैं? एक उदाहरण के रूप में – ceejayoz
। मैंने नोट किया कि कुछ एपीआई के आपूर्तिकर्ताओं (जैसे Google) आपको अपने दरवाजों पर बहुत बार बल्लेबाजी करने के लिए पसंद नहीं करते हैं। मैं टाइमर का उपयोग कर कॉल की आवृत्ति को कम करना चाहता हूं, लेकिन इसे लूप में उपयोग करने में परेशानी हो रही है, –
यह सच है, लेकिन आप हर बार एक ही अनुरोध के साथ अपने दरवाजे पर क्यों बैंग करेंगे? – ceejayoz