jQuery发布调用导致“无法加载资源:net :: ERR_INSUFFICIENT_RESOURCES"; [英] jQuery post calls resulting in "Failed to load resource: net::ERR_INSUFFICIENT_RESOURCES"

查看:12312
本文介绍了jQuery发布调用导致“无法加载资源:net :: ERR_INSUFFICIENT_RESOURCES";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,允许用户上传和映射CSV文件.完成此操作后,将通过邮寄呼叫将行发送到另一台服务器上的页面.经过将近6,00次呼叫(准确地说是5787次),我开始收到控制台错误无法加载资源:net :: ERR_INSUFFICIENT_RESOURCES".

I have a page that allows the user to upload and map an CSV file. After that is done, rows are sent through a post call to a page on a different server. After nearly 6,00 calls (5787 to be exactly), I start getting a console error of "Failed to load resource: net::ERR_INSUFFICIENT_RESOURCES".

我尝试运行CSV文件中包含100行的页面,但效果很好...但是当我尝试大型列表(超过10,000行)时,页面冻结了.

I've tried running the page with 100 rows in the CSV file, and it worked just fine... but when I tried a large list (over 10,000 row) it froze up.

以下是进行帖子调用的代码:

Here's the code making the post calls:

for (var i = 0; i < manifestRows.length; i++)
{
    $.post('http://www.otherserver.com/subfolder/handler.php', { tblName: 'foobar', thing1: manifestRows[i][0], thing2: manifestRows[i][1], thing3: manifestRows[i][2], thing4: manifestRows[i][3], thing5: manifestRows[i][4], thing6: manifestRows[i][5], thing7: manifestRows[i][6], thing8: manifestRows[i][7], thing9: manifestRows[i][8], thing10: manifestRows[i][9], thing11: manifestRows[i][10], thing12: manifestRows[i][11], thing13: manifestRows[i][12], thing14: manifestRows[i][13], thing15: manifestRows[i][14], thing16: manifestRows[i][15], thing17: manifestRows[i][16], thing18: manifestRows[i][17] }, function(data) {
    if (data.length == 0)
    {
        var currentProcessing = $('#processingCurrent').html();
        $('#processingCurrent').html(parseInt(currentProcessing) + 1);
        var progress = Math.ceil((parseInt(currentProcessing) / manifestRows.length) * 100);
        if (progress == 99)
            progress = 100;
        progress = progress + '%'
        $("#progressBar").width(progress).html(progress);
        if (progress == '100%')
        {
            $('#processdingDiv').hide();
            $('#allDone').show();
        }
    }
    else
        alert(data);
    });
}

是否可以在用户端或另一台服务器上放置一些代码,以防止发生此资源不足错误?

Is there some code I can put in either the user end, or on the other server to prevent this Insuffiecient Resource error from occuring?

推荐答案

我在AngularJS应用中遇到了几乎完全相同的错误.我要做的是批量处理请求.批次号是相对于您的实例的,但是我一次使用了1,000个呼叫.

I had almost the exact same error in an AngularJS app. What I had to do is batch the requests. The batch number is relative to your instance, but I used 1,000 calls at a time.

由于很多这种情况都是异步发生的,因此我不得不创建两个变量. httpRequestsExpected应该与批处理大小相同,具体取决于您的代码.在我的系统中,每次调用$http.$get();以获得确切值时,我都会对其递增.

Since a lot of this happens asynchronously, I had to create two variables. httpRequestsExpected should be same as batch size, depending on your code. In mine, I just incremented it every time I called $http.$get(); to get the exact value.

var batchSize = 1000;
var httpRequestsExpected;
var httpRequestsMade = 0;

var batchSize = 1000;
var httpRequestsExpected;
var httpRequestsMade = 0;

然后在http 成功和错误功能中,递增httpRequestMade.

Then in the http success and error functions, increment httpRequestMade.

要解决一个批次问题,并且由于http有时会挂起,我无法进行完全匹配,例如:
if(httpRequestsMade === httpRequestsExpected)
但必须这样填充:
if(httpRequestsMade >== httpRequestsExpected - (httpRequestsExpected *0.01))

To resolve a batch, and because http sometimes hangs, I couldn't do an exact match like:
if(httpRequestsMade === httpRequestsExpected)
but had to put in padding like this:
if(httpRequestsMade >== httpRequestsExpected - (httpRequestsExpected *0.01))

然后开始下一个批处理,将开始指针增加batchSize并重置变量.这样就为进程完成过程提供了安全的缓冲时间,而又不会浪费所有资源.

Then start the next batch, incrementing your starting pointer by batchSize and reset the variables. That provides a safe amount of buffering and time for the process to finish without consuming all the resources.

这篇关于jQuery发布调用导致“无法加载资源:net :: ERR_INSUFFICIENT_RESOURCES";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆