在我的项目( PHP ,提供的 Symfony的中2),我做了很多的阿贾克斯请求的每一页。我有很多问题与他们,因为它看起来像浏览器(在谷歌Chrome浏览器和火狐)被中止请求,没有给我一个错误。我做了一个干净的页面来测试什么可以导致此问题的错误仍然存在。我已经尝试了测试做了为
环路内10个请求(我相信我们不会有任何问题的,对吧?)。
In my project (PHP with Symfony 2) I do a lot of Ajax requests in every page. I'm having a lot of problems with them, because it looks like browsers (tested in Google Chrome and Firefox) are aborting requests without giving me an error. I've done a clean page to test what can be causing this issue and the error persists. I've tried a test doing 10 requests inside a for
loop (I believe we don't have any problem with it, right?).
下面是我的code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test page</title>
</head>
<body>Test page.
<script type="text/javascript" src="/js/compressed_jquery-1.8.2.min_1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
for (var i = 0; i < 10; i++) {
$.get('/i18n/javaScript/pt.json', function(data) {
console.log(data);
});
}
});
</script>
</body>
</html>
和这里的请求的截图导致萤火虫:
And here is a screenshot of requests result in Firebug:
正如你所看到的,一些请求完成,有些则没有。有时浏览器完成所有10个请求没有错误。有什么方法可以导致此?
As you can see, some requests are completed and others are not. Sometimes the browser completes all 10 requests without errors. What can be causing this?
我测试过的所有解决方案,但我pretty的肯定这是Windows,Apache或PHP配置问题。 // EN:今天我带的 VirtualBox的的运行的的Ubuntu 13.04 (铆足了劲猫熊)和Apache 2.2 + PHP,并且没有错误happenned,证明没有什么与我的 JavaScript的, HTML 或PHP code。我不知道这是一个配置问题。我怎么发现这个配置?
I've tested all the solutions, but I'm pretty sure it's a Windows, Apache or PHP configuration issue. Today I've configured a VM in my machine with VirtualBox running Ubuntu 13.04 (Raring Ringtail) with Apache 2.2 + PHP, and NO ERRORS happenned, proving that is nothing with my JavaScript, HTML or PHP code. I am not sure it is a configuration issue. How do I discover this configuration?
能否满足您的需求,发送请求一个接一个应该避免服务器拒绝一些并行请求:
Could fit your needs, sending request one by one should avoid server rejecting some parallel requests:
测试
$(document).ready(function () {
var tot = 30; //to simulate 30 requests
(function request(i){
if(i === tot) return;
$.get('/echo/html/?'+i, function (data) {
console.log("success");
}).always(function() { request(++i) });
})(0);
});