• Resolved ituk

    (@ituk)


    Hey,
    after using this wonderful plugin for several weeks i discovered today that the login handler calls ajaxStart for a different ajax function i run on a specific page.

    my login handler is .login-link.
    this is my ajax function on one of the pages:

    jQuery( '#indexForm' ).ajaxStart(function() {
    			   jQuery('#loading').fadeIn(200);  // show loading indicator
    			});
    
    			jQuery( '#indexForm' ).ajaxStop(function() {
    			   jQuery('#loading').fadeOut(200);  // hide loading indicator
    			});
    
    			jQuery('#indexForm').change(ajaxSubmit); //start the ajax index searching when option is selected
    			jQuery('#indexForm').submit(ajaxSubmit); //start the ajax index searching when submiting the form

    i search for a solution on stackexchange and found this answer: here. but i cannot find a way to implement it with the plugin/my code.

    i’d appreciate your help, thank you very much,
    Itamar

    https://www.ads-software.com/plugins/zm-ajax-login-register/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Zane Matthew

    (@zanematthew)

    Hi,

    Which version of ALR are you using? Is this is removed in the latest.

    Thread Starter ituk

    (@ituk)

    i’m using the latest (1.0.8) with small modifications for localization (css and language files)…

    itamar

    Plugin Author Zane Matthew

    (@zanematthew)

    Hi,

    This makes more sense now. The issue your experiencing is the way .ajaxStart() works, i.e., it attaches its self globally, as noted in the docs. Currently the only way to prevent this would be to set the global to false in .ajax().

    Its also worth noting that in the jQuery for docs for ajaxSetup they advise against using the global callback functions.

    Note: The settings specified here will affect all calls to $.ajax or Ajax-based derivatives such as $.get(). This can cause undesirable behavior since other callers (for example, plugins) may be expecting the normal default settings. For that reason we strongly recommend against using this API. Instead, set the options explicitly in the call or define a simple plugin to do so.

    .

    The ultimate (and only) solution would be for me to set global: false in the ALR .ajax() call.

    i.e., this code would change from:

    $.ajax({
        type: "POST",
        url: _ajax_login_settings.ajaxurl,
        data: {
            action: 'load_template',
            referer: 'login_form',
            template: 'login-form',
            security: $('#ajax-login-register-login-dialog').attr('data-security')
        },
        success: function( msg ){
            $( "#ajax-login-register-login-target" ).fadeIn().html( msg ); // Give a smooth fade in effect
        }
    });

    to this, note global: false:

    $.ajax({
        global: false,
        type: "POST",
        url: _ajax_login_settings.ajaxurl,
        data: {
            action: 'load_template',
            referer: 'login_form',
            template: 'login-form',
            security: $('#ajax-login-register-login-dialog').attr('data-security')
        },
        success: function( msg ){
            $( "#ajax-login-register-login-target" ).fadeIn().html( msg ); // Give a smooth fade in effect
        }
    });

    I will however add this to an issue on GitHub and have it in the next release.

    Plugin Author Zane Matthew

    (@zanematthew)

    I’ve added this as an issue on GitHub.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘ajax handler calls ajaxStart function on a specific page’ is closed to new replies.