且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery发布调用导致“无法加载资源:net :: ERR_INSUFFICIENT_RESOURCES";

更新时间:2022-06-25 16:54:52

我在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.