javascript - Not all Loops processed, only 5655 out of 13200 -
i have 2 javascript loops, 1 nested in other, ajax call serverside. loops generate pair of numbers (latlng coordinates), passed server via .getjson() inserted mysql table.
problem: script runs 6 minute, total of 13200 ajax calls. in chrome's webdeveloper tools, says 5656/13646 requests 536.20kb/2.15mb. when check tables inserted entries, see 5655 rows! happened rest?
js code
for(var = 0; < 110; i++) { var lat_current = lat_start + lat_increment * i; for(var j = 0; j < 120; j++) { // calculations // more code here... // insert latlng database $.getjson(base_url + 'insert_latlng_to_crawl', { lat: lat_current, lng: lng_current }, function(json){ }); } }
you should create javascript object, pass server , process server-side
var coords=array();//create array store calculations for(var = 0; < 110; i++) { var lat_current = lat_start + lat_increment * i; for(var j = 0; j < 120; j++) { // calculations // more code here... // append results array coords.push({lat: lat_current, lng: lng_current}); } //make ajax call server, sending completed array json encoded coords= json.stringify(coords); $.ajax({ type: 'post',//you should send big chunks of data via post url: url, data: coords, success: success, datatype: json });
Comments
Post a Comment