I'm having a bit of an issue with Ajax appearing inconsistent when loading my nodes. I initially followed the advice in this blog http://mrkadin.com/blog/node/70

which appears to work perfectly well. I extended my site to include JS built NEXT/PREV buttons. I tried to tie these buttons into using AJAX to load the node info in the same way as the view items work, but alas my results are terrible.

The links loaded by the view look like this:

<a rel="title1" class="use-ajax ajax-processed" href="/mysite/imgdisplay/nojs/8"><img src="http://localhost/mysite/sites/default/files/styles/thumbnail/public/image1.jpg?itok=ezLhXRk8"></a>

and here is my JS to add my NEXT link

jQuery('#nextbutton').append('<a class="use-ajax ajax-processed" href="http://localhost/mysite/imgdisplay/nojs/'+titles[0]+'" rel="'+titles[1]+'">Next ('+titles[1]+')</a>');

which is then rendered to this:

<a rel="title2" href="http://localhost/mysite/imgdisplay/nojs/7" class="use-ajax ajax-processed">Next (image2)</a>

The keyword NOJS can be altered to AJAX, if I build with nojs this causes the node to load normally, i.e. a new page opens. If I alter this to AJAX, then ajax load is attempted but the page switches and what looks like the raw ajax data is loaded into a html output like this


so I go on to try doing it outside of the drupal module route which the view is using and load it via ajax directly.

my next button now looks like this:

jQuery('#nextbutton').append('<a class="use-ajax jsclickdetect ajax-processed" href="#" rel="'+titles[0]+'">Next ('+title[1]+')</a>');

my listener:

    jQuery('#nextbutton a').live("click", function(){
        nid = jQuery(this).attr('rel');
  jQuery("#ajax-loader-area").load("http://localhost/mysite/imgdisplay/ajax/"+ nid);


now this causes this same code like dump, but at least its on my page where it should be.

looking into the console I see that the working AJAX load (via the view) runs as a POST where as my jQuery code runs as a GET, unknown if that's significant.

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.