Drupal.ajax not always on the page. On other pages I have an error: Uncaught TypeError: Cannot read property 'prototype' of undefined
I add it after line 6 in views_load_more.js

  if (Drupal.ajax == undefined) {
    return;
  }

Comments

ericduran’s picture

I'm pretty sure this is fixed in the 7.x version.

ericduran’s picture

Version: 7.x-1.1 » 7.x-1.x-dev

Seems like is still a bug. It should be noted, you need to enabled ajax in the views module in order for this to work.

Without it it throws the error, but I think it might be better to keep throwing the error so is obvious that views doesn't have Ajax enabled.

agalitsyn’s picture

Hmm, If I didn't enable ajax in view, pager will work without ajax. That's how I see that I didn't enabled it, not by js error in console.

Just imagine that I have page with view+views_load_more pager without ajax pagination. I have an js error in the console. At the same time I have button, which on click renders form in fancybox, and this form have ajax submit. This submit will not work because of error.

So I think this error shouldn't appear anyway. Pagination behaviour told us it's type (ajax/non-ajax)

ericduran’s picture

@agalitsyn it is type ajax/non-ajax. That being said using the views_load_more pager without ajax wouldn't be very good since the behavior would be that of a regular pager. It wouldn't be very performant to keep making the sql query render more and more data in a single call.

That being said this ajax error should still be fixed.

Also the idea behind non-ajax support is for when a user doesn't have JS enbled, the pager would still work as expected instead of not doing anything.

alarez’s picture

Proposed patch to avoid to declare viewsLoadMoreAppend function if Drupal.Ajax is not available. Error with JavaScript aggregation.

-enzo-’s picture

Status: Active » Reviewed & tested by the community

Tested with js aggregated and without aggregation

socialnicheguru’s picture

this works for me too

askibinski’s picture

I had a similar js aggregation/ajax problem in a custom module. Solved it by using:

/**
 * Implements hook_preprocess_html()
 */
function MYMODULE_preprocess_html() {
  drupal_add_library('system', 'drupal.ajax');
}

This way, ajax is included AND aggregation is fine. Before, I had it in hook_init or hook_node_view but that doesn't work. I think the js aggregator handles libraries differentyl in bundles.

ericduran’s picture

Status: Reviewed & tested by the community » Needs work

Neither of these fixes are correct for this module.

I'll just put up a patch soon to fix this issue. That being said this is only an issue if you're using it wrong. If you don't have ajax enable then the module isn't going to work as expected.

But yes this should be fixed.

oknate’s picture

To keep it within the module, I added the library in the theme function.

function theme_views_load_more_pager($vars) {
  global $pager_page_array, $pager_total;  

  drupal_add_library('system', 'drupal.ajax'); // added this line here
  drupal_add_js(drupal_get_path('module', 'views_load_more').'/views_load_more.js');

This seems to fix the issue for me.

socialnicheguru’s picture

#9 eridduran, on the homepage it says the following: "Provide ajax/no-ajax views load more".

So shouldn't the module work even if the view is not ajax enabled?

attila.fekete’s picture

Status: Needs work » Needs review
StatusFileSize
new881 bytes

Attached patch to avoid undefined ajax error. views_load_more.js is only included if ajax is enabled.

pwolanin’s picture

This looks like a pretty simple fix

attila.fekete’s picture

K_Gonzalez’s picture

Hello,

I used the version 7.x-1.2 of Views Load More and i have the same error ( with firebug). The patch of #12 it's already in the code. Many people have this problem ?

EDIT : if the line 16 var targetList = response.targetList || ''; is comment this resolve the error but is not a good solution
Sorry if my english it's bad.

Cordially

Issue tags: +
m4olivei’s picture

Issue summary: View changes
Status: Needs review » Closed (fixed)

Looks like this was resolved and commited.

@K_Gonzalez if your still having an issue. Please detail it including steps to reproduce in a new issue.

gambry’s picture

You probably want to have a look at #2721591: Drupal.ajax is undefined and see if the same issue would apply to views_load_more and/or if the improved condition will be beneficial.