Hi,

Not sure what I'm doing wrong here. Really simple scenario. I have 3x links to load 3x different html files into the target div, depending on which I click. After I load the page I can click any of the links and they work but nothing happens when I click again - the target div never changes after the first time.

<div class=\"landlordstenants-q\">
<ul>
<li><a class=\"ajax-link1\" href=\"sites/default/files/snippets/landlords/1.html\" rel=\".landlordstenants-a\">Link 1</a></li>
<li><a class=\"ajax-link1\" href=\"sites/default/files/snippets/landlords/2.html\" rel=\".landlordstenants-a\">Link 2</a></li>
<li><a class=\"ajax-link1\" href=\"sites/default/files/snippets/landlords/3.html\" rel=\".landlordstenants-a\">Link 3</a></li>
</ul>
</div>
<div class=\"landlordstenants-a\">
</div>

Please ignore the backslashes - it's because the code is inside a php statement.

Any help would be appreciated.

Thanks,

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

robriley78’s picture

Just to add - I tried a more complex scenario - different link class, different target div etc. Same problem. I can basically only make one Ajax call per page load.

robriley78’s picture

Sort of solved. It doesn't like the fact that I'm trying to load my own HTML files - it works fine if I try to load other nodes. I can work with this but if anyone knows why it would be good to know/understand.

Great module though. Saved me some time :)

zwoelfgrad’s picture

I had the same issue when i override the html--ajax.tpl.php. I had to remove everything but "print $page" in the overridden tpl, because twice loaded scripts breaked some js in my single page application.

The problem was: the variable "ajaxLoading" was not reset after the ajax call. Putting a line at the end of the success function solved the problem for me.

success: function (data, textStatus, xhr) {
        $(selector).html(data);
		Drupal.attachBehaviors(selector);
		
		var html5 = Drupal.settings.ajax_links_api.html5;
		if(html5 == 1) {
		  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.
		}
	        //variable reset here
		ajaxLoading = false;	
      },

Hope this helps.

serjas’s picture

Status: Active » Needs review

@robriley78 please update on issue. So i can close this issue

Rob C’s picture

serjas i've found the same issue, that ajaxLoading = false; indeed need to be added, see this patch.

Status: Needs review » Needs work

The last submitted patch, ajax-links-api-ajaxloading-fix.patch, failed testing.

Rob C’s picture

Version: 7.x-1.7 » 7.x-1.x-dev
Category: support » bug
Status: Needs work » Needs review

@zwoelfgrad
This could also be interesting for you https://drupal.org/node/1989532 I'm working on the same idea i guess.

serjas’s picture

Status: Needs review » Active

@Rob C and zwoelfgrad,

If you remove $scripts from html-ajax.tpl.php, this issue may arise. But we cant have a general solution for this as you suggested. I tried removing $scripts and included context and ajaxLoading = false. Everything works fine but when i tried to ajaxify node/add/page with ahah image upload, it is not working! when i include $scripts, it works!

floorfi’s picture

On my page a problem, similar to post #1, apears.
One page has different ajax-Links which should change a div-container on the same site. With click on one of these links, the content is correctly loaded to the container. Each following click on one of those links has no effect.

Im only loading drupal-nodes and further didn't changed anything at the templates.

Another problem is (maybe similar reasons?), that if I try to load a view with an accordion-layout to the container, the accordion script dosn't work.

andregriffin’s picture

Similar issues here. When I remove $scripts, my ajax div doesn't update with new content after the first load. When I include $scripts, the ajax load works fine, but then my Bootstap js menus don't work after ajax has been used.

My use case is ajax loading nodes into a modal window in a gallery style view. After closing the window, js dropdown menus don't work.

Edit: Patch in #5 seemed to solve my particular issue.
Edit2: Strangely, it only works if I have <title><?php print $head_title; ?></title> in the tpl, along with <?php print $page; ?>

olofbokedal’s picture

Status: Active » Needs review
FileSize
438 bytes

Created patch for the latest dev.

All that's needed is to update the ajaxLoading variable after the call has been made. This is a boolean that indicates whether or not a call should be allowed.

serjas’s picture

committed to latest dev

serjas’s picture

Status: Needs review » Active
andregriffin’s picture

New strange symptom and followup on #10. Now, dropdown menus work after every other ajax call. After the first call menus don't work, after the third they do, after the forth they don't, etc.

serjas’s picture

@andregriffin , have you tried latest 1.83?

andregriffin’s picture

Yes, that is my current version

mxwitkowski’s picture

Hi - I can report similar behavior. Using the latest version of the module v1.8.3 on a site with superfish drop menus (v7.x-1.9 from 4/27/13). The menus work fine when I first load my main page, once I interact with the page and load content into a div with the Ajaxify Drupal with JQuery Ajax module, my menus stop working. As soon as I navigate to and load another page on the site, the menus begin working again.

I have debugged for a bit and can't seem to locate the root cause - but it sure seems to be related. I also applied the patch from #11 and had no luck in resolving the issue. I also disabled the HTML5 page title option and removed the echo $head_title; in html--ajax.tpl.php; still no luck in getting the menus working after the initial load.

I have tested in IE9, Firefox on the Mac and Chrome on the Mac -- all are showing the exact same behavior.

serjas’s picture

Issue summary: View changes
Status: Active » Fixed

Added a admin settings to uncheck , if $scripts are removed. Updated in latest DEV. Please test and confirm

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

drwits’s picture

Sorry to open this thread again.
With scripts removed I only get one page load. I'm on the current dev release and I don't see an admin settings to uncheck if $scripts are removed.

Thanks.

serjas’s picture

Status: Closed (fixed) » Active
peezy’s picture

I was having the same issue with Ajax only loading on the first click, but here's how to fix it:

  • Update to the latest dev (as suggested in #18)
  • Flush all caches
  • Uncheck the box labelled "Included $scripts in tpl" at /admin/config/development/ajax-links-api
  • Click save.
bocaj’s picture

I was having the exact same issue ... I followed @peezy's post in #22 at everything works as I expected! Thanks!

trackleft2’s picture

on line 104 of ajax_links_api.js

    // To check if the url ends with the link.                                                                                                                                                                                  
  1     $('a').filter(function() {                                                 
  2       return url.endsWith($(this).attr('href'));                               
  3     }).addClass('active').parents('li').addClass('active-trail');  

Should be:

$('a[href$="' + url +'"]').addClass('active').parents('li').addClass('active-trail');

Reference

v8powerage’s picture

How about fix for 6.x?

PQ’s picture

We could really do with having a new stable release as the current one (7.x-1.83) is fundamentally broken due to ajaxLoading = false; being removed from ajaxAfter() in http://cgit.drupalcode.org/ajax_links_api/commit/?id=50d4cd48efc38ecb5b4....

It's fixed in dev but until there's a 7.x-1.84 people will keep downloading the module and finding it broken.

Not sure what the situation is with the 6.x branch.

candelas’s picture

Yes, it would be nice a new release because you get the stable release, get problems, go to the issues and find this... and get the dev.
Thanks for the module and please, release a new version :)

garvin’s picture

I was having a similar issue. I don't remember how I found the solution but in my case, I disabled textarea.js. I only remembered because after a core update, I discovered that my ajax forms would not work twice. I had forgotten that I had hacked it long ago. I found this solution in my old notes.

Find it here:
/misc/textarea.js

I did this to disable it:

/misc/textarea.js_disabled

Not very elegant but it worked. I'm sure there's a better method for solving the conflict.