Hello.

Sorry for my english i am french.

I found a bug in the module. At the first click there is no problem. The second click, the page is loading two times. The third click, the page is loaded 4 times. So on. This slowed considerably navigation.

French version : J'ai détecté un bug dans le module. Lors du premier clique il n'y a aucun problème. Au deuxième clique, la page est charger 2 fois. Au troisième clique, la page est charger 4 fois. Ainsi de suite. Cela ralentie considérablement la navigation.

Thank you

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fotisp’s picture

hello there,
I was facing a similar problem, i'm loading some blocks that containing the ajax links into node.tpl
Everything was working fine exept the multiple load when clicking the ajax links ..
Based on http://www.electrictoolbox.com/jquery-prevent-ajax-request-firing-twice/
i modified the ajax_links_api.js

(function ($) {
var ajaxLoading = false;
 Drupal.behaviors.ajaxLinksApi = {
    attach: function (context, settings) {      
      $("a.ajax_link").click(function(e) {  
		e.preventDefault();
		 if(!ajaxLoading) {
            ajaxLoading = true;
			            var url = $(this).attr("href");
        var id = $(this).attr("rel");
		$(id).html("<div class='loading'></div>");
		ajaxLink(id, url, 
		function() { ajaxLoading = false;
                }
            );
        }
		
        
		});
    }
  };
  function  ajaxLink(id, url) {
    $.ajax({
      url: url,
      type: "GET",
      data: "ajax=1",
      success: function (data, textStatus, xhr) {
        $(id).html(data);
		Drupal.attachBehaviors(id);
        var title = data.match("<title>(.*?)</title>")[1]; // get title of loaded content	
		window.history.pushState( {} , document.title, window.location.href ); // change title and url	
		window.history.replaceState( {} , title, url ); // Change url.
		document.title = title; // Since title is not changing with window.history.replaceState(), manually change title. Possible bug.
      },
      error: function (xhr, textStatus, errorThrown) {
        $(id).html("Access denied or page not found");
      }
    });
  }
})(jQuery);

I'm not a coder, however it makes the trick for me.

thanks,
F

sebastien247’s picture

This code doesn't work for me. i've modified this one

(function ($) {
var ajaxLoading = false;
 Drupal.behaviors.ajaxLinksApi = {
    attach: function (context, settings) {      
      $("a.ajax_link").click(function(e) {  
		e.preventDefault();
		 if(!ajaxLoading) {
			ajaxLoading = true;
			var url = $(this).attr("href");
			var id = $(this).attr("rel");
			$(id).html("<div class='loading'></div>");
			ajaxLink(id, url);
		}
	});
    }
  };
  function  ajaxLink(id, url) {
    $.ajax({
      url: url,
      type: "GET",
      data: "ajax=1",
      success: function (data, textStatus, xhr) {
        $(id).html(data);
		Drupal.attachBehaviors(id);
        var title = data.match("<title>(.*?)</title>")[1]; // get title of loaded content	
		window.history.pushState( {} , document.title, window.location.href ); // change title and url	
		window.history.replaceState( {} , title, url ); // Change url.
		document.title = title; // Since title is not changing with window.history.replaceState(), manually change title. Possible bug.
      },
	  complete: function(xhr, status){
		ajaxLoading=false;
	  },
      error: function (xhr, textStatus, errorThrown) {
        $(id).html("Access denied or page not found");
      }
    });
  }
})(jQuery);

this one works for me

serjas’s picture

Assigned: sebastien247 » serjas
Status: Active » Needs work
serjas’s picture

Status: Needs work » Postponed (maintainer needs more info)

Hi sebastien247,

I cant reproduce issue. Can you give details how to reproduce same issue?

pipicom’s picture

Have the same problem; fotisp solution seems to work for me also.

fotisp’s picture

Hi serjas,
It seams that the problem occurs when the ajax links are inside the ajaxible content area. (so the links are reloaded)
Thx
F

serjas’s picture

Status: Postponed (maintainer needs more info) » Needs review

Thanks @fotisp

Committed to 7.x-1.x . please review

serjas’s picture

@fotisp
@sebastien247
@pipicom

Please review

pipicom’s picture

Latest dev works for me!
However even I have removed your comments on 'ajax_links_api.js', I cannot make the H1 title refresh properly..

serjas’s picture

Status: Needs review » Closed (fixed)

Applied to 7.x-1.5 (http://drupal.org/node/1831952)

:)

serjas’s picture

@pipicom , please post the issue in http://drupal.org/node/1808310 . It works only for HTML5 browsers. I think it is still unsupported in major browsers. Works fine in Chrome 22.0

pipicom’s picture

You 're correct.. Thanks for the prompt answer (again!)..

sachbearbeiter’s picture

wasn't there a convention to work with this classes?
http://drupal.stackexchange.com/questions/29348/jquery-code-is-loading-c...

anyway - thanks for fix ...

sb

windmaomao’s picture

I had the same issue, the page will load slower and slower and slower.

Basically i have a block and content region, and the link is inside block. It's weird it'll cause this issue. Because my link isn't in the content.