jquery - How to avoid out of memory error in a browser due to too many ajax calls -
i'm building web application needs make 28000 database calls using jquery ajax shortform @ once.
it gets through 6000 of calls fine, browser gives me 20000 of following error (one each call) in browser console:
post (my database call) net : : err_insufficient_resources
does know how around this? maybe create buffer or something?
thanks!
edit 1 : adding code:
aright, user fill in values (say ghi > 4500, aspect between 157.5 , 202.5)
the following call made:
loadalldata('ghi', 4500, findidealpoints); this call leads function:
function loadalldata(type, above, callback){ var data = {}; $.post('php/getidealdata.php?action=get&type='+type+'&above='+above, data, callback); }
which runs query in php:
"select `ghi` , `lat` , `long` solar `ghi` >'{$_get['above']}' order `lat`,`long`;"; that returns 28880 records in array in json format , calls callback method following:
function findidealpoints(data){ var = 0; while (i < data.length){ loadaspectwithinrange('aspect', data[i]['lat'], data[i]['long'], 10, comparewithaspect); i++; } }
which runs php query:
"select `aspect`, `lat`, `long`, distance_in_km ( select `aspect`, `lat`, `long`,r, (6378.10 * acos(cos(radians(latpoint)) * cos(radians(`lat`)) * cos(radians(longpoint) - radians(`long`)) + sin(radians(latpoint)) * sin(radians(`lat`)))) distance_in_km aspect join ( select '{$_get['lat']}' latpoint, '{$_get['long']}' longpoint, 10.0 r ) p `lat` between latpoint - (r / 111.045) , latpoint + (r / 111.045) , `long` between longpoint - (r / (111.045 * cos(radians(latpoint)))) , longpoint + (r / (111.045 * cos(radians(latpoint)))) , `aspect` between '{$_get['lowa']}' , '{$_get['higha']}' ) d distance_in_km <= r order distance_in_km"; and goes callback function runs this:
function comparewithaspect(data){ var idealpoints =[]; (var i=0; i<data.length; i++){ idealpoints.push(new google.maps.latlng(data[i]['lat'], data[i]['long'])); } if (idealpoints.length > 1){ makepolygon(idealpoints) } } and makepolygon draws on map using google maps api.
i know it's lot , seems convoluted, love if show me better way this!
thanks again
you this.
function findidealpoints(data){ var = 0; while (i < data.length){ loadaspectwithinrange('aspect', data[i]['lat'], data[i]['long'], 10, comparewithaspect); i++; } instead of doing ajax call each occurrence send data object call
loadaspectwithinrange('aspect',data,10,comparewithaspect) then in ajax request send array of objects service , retrieve results of them instead of 1 one.
$.ajax({ url:"...", data:{ attr1:'aspect', points: data(here array retrieved "getidealdata.php") attr2: 10 }, success:function(data){ comparewithaspect(data) } }) in server side processing build array of objects element on getidealdata.php points.
this better instead of doing ajax each element
Comments
Post a Comment