我正在使用此 ajax 代码来检查域。对于每个域,都会向 API 发送一个请求。我在带有 3 个后缀(6000 个域)的 textarea 中创建了 2000 行,然后单击提交。提交所有检查过的域后,使用 ajax 在表中显示域状态。第一次显示域表,但几秒钟后表被删除,代码不显示结果!
如何解决这个问题?
Chrome 的控制台显示此错误:
Failed to load resource: net::ERR_INSUFFICIENT_RESOURCES
Ajax code(ajax.js):
$(document).ready(function () {
$("#submit").click(function () {
// check if anything is selected:
if(!$('#domains').val() || !$('[type="checkbox"]:checked').length){
return false;
}
// disable the button:
var btn = $(this).prop('disabled', true);
var domain = $('#domains').val().split("\n");
var counter = 0;
// an indicator to state when the button should be enabled again:
var ajaxQueue = 0;
//send ajax request for earse txt file (new request)
$.ajax({
type: "GET",
url: "includes/ajax/ajax.php",
data: {new_request: ajaxQueue },
});
var Table = '<table class="paginated table table-bordered table-striped table-responsive domain-table"><thead><tr><th>ID</th><th>Domain Name</th><th>.Com</th><th>.Net</th><th>.Org</th><th>.Ir</th><th>.Biz</th><th>.Info</th><th>.Us</th><th>.Name</th><th>.Pro</th><th>.Eu</th><th>.In</th><th>.Me</th><th>.Tv</th><th>.Cc</th></tr></thead><tbody>';
// create the td elements, but do not perform AJAX requests there:
$.each(domain, function (i, val) {
counter++;
Table += '<tr><td>'+ counter +'</td><td>'+ val +'</td>';
$('input[type=checkbox]').each(function () {
if($(this).is(':checked')){
ajaxQueue++;
// if checkbox is checked make td element with specified values and a "load-me" class:
Table += '<td class="load-me" data-domain="'+val+'" data-suffix="'+$(this).val()+'"><small>loading...</small></td>';
}else{
Table += '<td><span class=text-muted><i class="fa fa-minus"></i></span></td>';
}
});
Table += '</tr>';
});
// Replace HTML of the 'domain_tables' div and perform AJAX request for each td element with "load-me" class:
$('#domain_tables').html(Table+'</tbody></table>').find('td.load-me').each(function(){
var td = $(this);
$.ajax({
type: "POST",
url: "includes/ajax/ajax.php",
dataType: "json",
data: {domain: td.attr('data-domain'), suffix: td.attr('data-suffix')},
success: function (msg) {
// decrease ajaxQueue and if it's 0 enable button again:
ajaxQueue--;
if(ajaxQueue === 0){
btn.prop('disabled', false);
}
if(msg.suc == false){
td.html('<span class=text-danger><i class="fa fa-check"></i></span>');
}else{
td.html('<span class=text-success><i class="fa fa-times"></i></span>');
}
},
error: function (err) {
$('#domain_tables').html(err.error);
}
});
});
// clear textarea and uncheck checkboxs
$("#reset").click(function(){
$('input[type=checkbox]').attr('checked', false);
$('#domains').val('');
$('#submit').prop('disabled', false);
});
// table paganation
$('table.paginated').each(function() {
var currentPage = 0;
var numPerPage = 100;
var $table = $(this);
$table.bind('repaginate', function() {
$table.find('tbody tr').hide().slice(currentPage * numPerPage, (currentPage + 1) * numPerPage).show();
});
$table.trigger('repaginate');
var numRows = $table.find('tbody tr').length;
var numPages = Math.ceil(numRows / numPerPage);
var $pager = $('<ul class="pager pagination"></ul>');
for (var page = 0; page < numPages; page++) {
$('<li class="page-number"></li>').text(page + 1).bind('click', {
newPage: page
}, function(event) {
currentPage = event.data['newPage'];
$table.trigger('repaginate');
$(this).addClass('active').siblings().removeClass('active');
}).appendTo($pager).addClass('clickable');
}
if(numRows > 100 ){
$pager.insertAfter($table).find('span.page-number:first').addClass('active');
}
});
});
});
PHP代码(ajax.php):
<?php
if($_SERVER['REQUEST_METHOD']=='GET'){
$new_request = $_GET['new_request'];
// check new request flag for erase all data from txt file
if(isset($new_request) && $new_request == 0 ){
$handle = fopen ("../textfile/data.txt", "w+");
fclose($handle);
}
}
if($_SERVER['REQUEST_METHOD']=='POST'){
$domain = $_POST['domain'];
$suffixes = $_POST['suffix'];
$target = 'http://whois.apitruck.com/'.$domain.".".$suffixes;
$getcontent = file_get_contents($target);
$json = json_decode($getcontent);
$status = $json->response->registered;
if($status){
die(json_encode(array('suc'=>true)));
} else {
$file = '../textfile/data.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= $domain.".".$suffixes." | \n";
// Write the contents back to the file
file_put_contents($file, $current);
die(json_encode(array('suc'=>false)));
}
}
?>
最佳答案
根据 Chrome 的代码审查,您收到该错误的原因是您达到了渲染过程中可以处理多少请求的限制,正如您所提到的 - 您说的是大约 6000 个请求。
错误:
net::ERR_INSUFFICIENT_RESOURCES
原因:
Add a constraint on how many requests can be outstanding for any given render process (browser-side).
Once the constraint is reached, subsequent requests will fail with net::ERR_INSUFFICIENT_RESOURCES.
The bound is defined as "25 MB", which represents the amount of private bytes we expect the pending requests to consume in the browser. This number translates into around 6000 typical requests.
Note that the upload data of a request is not currently considered part of the request's in-memory cost -- more data is needed on the average/maximum upload sizes of users before deciding what a compatible limit is.
来源:https://codereview.chromium.org/18541
如何解决?
我的建议是获取输入并将其添加到数据库中,添加到一个pending_requests 表中。在您的服务器中,创建一个每隔几分钟运行一次的 cronjob,并完成来自该表的 X 个请求,一旦完成 - 从该表中删除它们,以便下次运行 cronjob 时它将转到下一个 X 个请求。
许多处理多请求的服务以某种方式使用这种方法。他们通常在任务完成时通过电子邮件通知用户。
关于javascript - Chrome下加载资源失败!目前不工作ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28939913/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request
在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo
我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("
我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub