jQuery的Ajax请求没有得到完成 [英] jQuery ajax request doesn't get completed

查看:124
本文介绍了jQuery的Ajax请求没有得到完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临一个奇怪的问题,其中,当后续的请求是由Ajax请求没有得到完成。

I'm facing a weird issue in which the ajax requests doesn't get completed when subsequent requests are made.

当网页加载第一次Ajax调用工作正常。但是,如果我调用同样的方法而无需刷新页面,则请求永远不会完成,即使是Apache没有响应。我检查apache的错误日志,发现如下条目:

The ajax calls works fine when the web page is loaded first time. But if I invoke the same method without refreshing the page, then the request never get completed and even apache is not responding. I checked apache error logs and found the following entry:

[Tue Nov 01 16:41:42 2011] [error] server reached MaxClients setting, consider raising the MaxClients setting

下面是我试图执行的jQuery code:

Here is the jQuery code which I am trying to execute:

(function($) {
    $(function(){

        form = $('form.crud');
         $("#end_date").datepicker({dateFormat: 'yy-mm-dd'});

/** Contract Comments **/
        $('#actionbar ul li:nth-child(1) a').colorbox({
            scrollable: false,
            innerWidth: 600,
            innerHeight: 280,
            href: SITE_URL + 'admin/contracts/comments/create_ajax',
            onComplete: function() {
                $.colorbox.resize();
                $('form#comments').removeAttr('action');
                $('form#comments').live('submit', function(e) {
                    var form_data = $(this).serialize();

                    $.ajax({
                        url: SITE_URL + 'admin/contracts/comments/create_ajax',
                        type: "POST",
                            data: form_data,
                        success: function(obj) {
                            if(obj.status == 'ok') {
                                $.colorbox.close();
                            } else {
                                $('#cboxLoadedContent').html(obj.message + obj.form);
                                $('#cboxLoadedContent p:first').addClass('notification error').show();
                            }
                        }
                    });
                    e.preventDefault();
                });
            }
        });
    });
})(jQuery);

这似乎在浏览器充斥冗余请求的服务器。确实是有意义的增加MaxClients的数(目前为256 prefork MPM和300工人MPM。

It seems the browser is flooding the server with redundant requests. Does it makes sense to increase the MaxClients count(currently it is 256 for prefork MPM and 300 for worker MPM.

推荐答案

看来你有效地充斥你的网络服务器。您应该使用类似Firebug或Chrome开发者工具的工具,看看您发送Ajax请求的数量。

Seems that you're effectively flooding you webserver. You should use a tool like Firebug or Chrome developers tools and have a look at the number of ajax requests you are sending.

我恳求在 $('形式#意见)的现场活动。生活('提交',函数(E){运行几次(同检查一个的console.log(附加现场活动'); )尽量避免现场活动或至少在你绑定事件元素添加一个类,让你可以过滤您的生活事件选择器,以避免绑定一个已经绑定的。

I beg the live event in $('form#comments').live('submit', function(e) { is running several times (check it with a console.log('attaching live event');). Try to avoid live events or at least add a class in your binded event element so that you could filter your live event selector to avoid binding an already binded one.

这应该工作:

$("form#comments:not(.live-submit-binded)")
   .addClass('live-submit-binded')
   .live('submit', function(e) {
    (...)
});

这篇关于jQuery的Ajax请求没有得到完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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