1

I can't get jQuery's ajaxComplete to work. I'm thinking it's because the ajax call is being initialised by Prototype? But how can I check when any ajax call This is basically the code I have:

jQuery(document).ready(function() {

    function popupInit() {
        jQuery('.popup-window').click(function() {
            // rest of code here
        });
    }
    popupInit();
    jQuery(document).ajaxComplete(function(){
        console.log( "Triggered ajaxComplete handler." );
        popupInit();
    });
});

I checked in the Chrome sources panel and after an XHR response has finished my function is not called an neither is the console.log.

I'm not initiating the ajax call it's coming from a extension for our Magento website:

    new Ajax.Request(url, {
        method: 'post',
        onSuccess: function(transport)    {
        if(transport.status == 200)    {

            var data = transport.responseText.evalJSON();

            // Update shipment methods
            if(shipment_methods_found)  {
                shipment_methods.update(data.shipping_method);
            }

            if(update_payments){
                payment_methods.replace(data.payment_method);
            }

            totals.update(data.summary);


        }
    },
    onComplete: function(transport){
        if(transport.status == 200)    {
            if(shipment_methods_found)  {
                $$('dl.shipment-methods input').invoke('observe', 'click', get_separate_save_methods_function(set_methods_url, update_payments));
                $$('dl.shipment-methods input').invoke('observe', 'click', function() {
                    $$('div.onestepcheckout-shipment-method-error').each(function(item) {
                        new Effect.Fade(item);
                    });
                });
            }

            if(update_payments){
                $$('div.payment-methods input[name="payment\[method\]"]').invoke('observe', 'click', get_separate_save_methods_function(set_methods_url));

                $$('div.payment-methods input[name="payment\[method\]"]').invoke('observe', 'click', function() {
                    $$('div.onestepcheckout-payment-method-error').each(function(item) {
                        new Effect.Fade(item);
                    });
                });

                if($RF(form, 'payment[method]') != null)    {
                    try    {
                        var payment_method = $RF(form, 'payment[method]');
                        $('container_payment_method_' + payment_method).show();
                        $('payment_form_' + payment_method).show();
                    } catch(err)    {

                    }
                }
            }
        }
    },
    parameters: parameters
    });
  • Is jQuery's ajax complete not working as the ajax request is being initialised by prototype?
  • How can I check with JavaScript when any ajax response is complete?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.