How to avoid out of memory error in a browser due to too many ajax calls

后端 未结 1 353
广开言路
广开言路 2020-12-21 10:34

I\'m building a web application that needs to make about 28000 database calls using the jquery ajax shortform all at once.

It gets through about 6000 of the calls fi

相关标签:
1条回答
  • 2020-12-21 11:21

    You could do something like this.

    function findIdealPoints(data){
       var i = 0;
        while (i < data.length){
           loadAspectWithinRange('aspect', data[i]['lat'], data[i]['long'], 10,          
         compareWithAspect);
        i++;
    }
    

    Instead of doing an Ajax call for each occurrence send the data object to your call

     loadAspectWithinRange('aspect',data,10,compareWithAspect)
    

    Then in the Ajax request send the array of objects to your service and retrieve the results for all of them instead of one by one.

    $.ajax({
       url:"...",
       data:{
           attr1:'aspect',
           points: data(here is the array retrieved from "getIdealData.php")
           attr2: 10
        },
       success:function(data){
          compareWithAspect(data)
       }
    })
    

    In the server side processing build an array of the objects for all the element on the getIdealData.php points.

    This will be better instead of doing an Ajax for each element

    0 讨论(0)
提交回复
热议问题