TypeError: D.ajax is undefined
var beforeSerialize = D.ajax.prototype.beforeSerialize;

On jquery_update.js line 2

jQuery 1.7

Comments

vvs’s picture

Issue summary: View changes

page

vvs’s picture

Issue summary: View changes

code

mathieso’s picture

Seems to be:

drupal_add_js('misc/ajax.js');

When this is included, I get the error. When not there, no error.

jQuery 1.8.

mathieso’s picture

Hmm...

Wrapped the contents of jquery_update.js like this:

jQuery(document).ready(function() { 

(function (D) {
  var beforeSerialize = D.ajax.prototype.beforeSerialize;
  D.ajax.prototype.beforeSerialize = function (element, options) {
    beforeSerialize.call(this, element, options);
    options.data['ajax_page_state[jquery_version]'] = D.settings.ajaxPageState.jquery_version;
  }
})(Drupal);

});

Delays code execution until after Drupal is defined.

No error message. The JS code was executed (set a breakpoint to find out). Whether it has the intended effect, I don't know.

Kieran

paulsheldrake’s picture

StatusFileSize
new870 bytes

Here is patch to fix this problem based off the solution mathieso provided.

For pages with complex js this could slow down rendering so ideally we would find out why the ajax property doesn't exist at when the code is called but I think this is decent enough solution in the short term.

paulsheldrake’s picture

Status: Active » Needs review
Punk_UnDeaD’s picture

maybe I'm wrong
but at this point in the design bug fixes

OnkelTem’s picture

IMHO this is design error.

drupal.ajax is set dependent on jquery_update.ajax.fix by JQuery Update:

$javascript['drupal.ajax']['dependencies'][] = array('jquery_update', 'jquery_update.ajax.fix');

which makes jquery_update.js to load BEFORE ajax.js — i.e. before Drupal.ajax becomes declared.

OnkelTem’s picture

Priority: Normal » Major

This must be resolved as it breaks things.

Anonymous’s picture

Running into this problem today, can't run js menus on my site.

Anonymous’s picture

Just an FYI. The patch in #3 did not resolve the problem. I had to disable jquery update module to get javascript working again on my site...

dzinergal’s picture

Hi I'm getting a site wide ajax error on fields in the backend.

I've disabled the Jquery update module and still getting that error.

Not sure where to go from here. Anyone able to shed some light?

Thanks ;)

dzinergal’s picture

Issue summary: View changes

version

OnkelTem’s picture

Sorry, comments from #6 and #7 are invalid. They should be edited or removed.

OnkelTem’s picture

Priority: Major » Normal
Issue summary: View changes

Looks like something is breaking load sequence. In my situation (invalid comments #6 and #7) the reason was REL module, which simply did drupal_add_js('misc/ajax.js'); and this was breaking weight of already prepared ajax.js library.

matsjacobsson’s picture

I too get this problem when using Commerce Ajax Cart (https://drupal.org/project/commerce_ajax_cart). When I disable that module the error disappear.

The patch in #3 works for me though. So thanks! /Mats

Exploratus’s picture

Patch # 3 worked for me, at least in the interim. The error was causing my subsequent scripts to hang.

anybody’s picture

Confirming #13!

anybody’s picture

Priority: Normal » Major

Set the priority to major because it breaks functionality on a wide range and seems to be a design bug. Hope you agree.

ericduran’s picture

Hmm, This looks like it was introduce when we added the option to use different versions of jquery for admin pages.

Can someone confirm this is an issue if you're only using one version of jQuery, or is this happening always even if you don't use a different version for admin pages.

sinasalek’s picture

It happens with all version of jquery for me
patch in #3 fixed the problem

ericduran’s picture

Yea, this patch doesn't look right, this is definitely a design error, This file should be loaded after drupal ajax not before it.

ericduran’s picture

The proper fix for this would probably be removing the jquery_update.ajax.fix library and instead adding that file into the drupal.ajax_library after the ajax.js file.

This way it's always included right after it.

If someone is interested if not it'll have a patch later tonight.

adamgerthel’s picture

Any news on the patch? Also using Commerce Ajax cart and have the same issue. Should this be moved there?

Punk_UnDeaD’s picture

> Also using Commerce Ajax cart and have the same issue. Should this be moved there?

bug in Commerce Ajax cart

joelpittet’s picture

StatusFileSize
new1.3 KB

@ericduran I tried to give that a shot but failed miserably :( Can't stand the render array API...

Here's the patch just in-case it's half way there for you...

ParisLiakos’s picture

i think #20 means something like the attached patch...
for me it is only broken in IE8 and the attached patch does not fix it

(See screenshot)

I show that IE complains about ajax.js..so i went in line 625..and changed new to newz just to see what happens..i refreshed the page and the error was gone...

so maybe this is a drupal core bug? since this line was introduced in drupal 7.27 and http://drupalcode.org/project/drupal.git/commit/6642fbc

ParisLiakos’s picture

socialnicheguru’s picture

Issue tags: +commerce ajax cart, +commerce_ajax_cart

this is definitely a commerce_ajax_cart issue. If I install it ajax just breaks. Too bad.

I'll leave it to better minds than mine to switch the issue to that queue.

maxilein’s picture

commerce_ajax_cart issue solution (not yet committed): https://www.drupal.org/node/2280465

joelpittet’s picture

@maxilein Does the latest patch there solve the problem, if so I'll commit it. It needs review/rtbc.

maxilein’s picture

@joelpittet it solves the problem of the commerce_ajax_cart breaking jquery_update for rules. Yes.

czigor’s picture

Status: Needs review » Needs work

Rerolled #24 but it does not work for me, I still get the same error message in console. I don't have commerce_ajax_cart.

Punk_UnDeaD’s picture

@czigor
bug in Commerce Ajax cart

drupal_add_js('misc/ajax.js'); //WTF?
drupal_add_library('system', 'drupal.ajax'); //good

Punk_UnDeaD’s picture

Status: Needs work » Closed (works as designed)
czigor’s picture

Status: Closed (works as designed) » Needs work

I still have this bug.

Punk_UnDeaD’s picture

Status: Needs work » Closed (works as designed)

> I still have this bug.

So what?

when I use commerce_ajax_cart, I have bug
I replace stupid code in commerce_ajax_cart_preprocess_html

  drupal_add_js('misc/ajax.js',array('type' => 'file' , 'weight' => -100 ));

on

  drupal_add_library('system', 'drupal.ajax');

and I feel good

drupal.ajax - is library, not single js

czigor’s picture

Status: Closed (works as designed) » Needs work

But I can't do that since I don't have commerce_ajax_cart and still have this bug.

joelpittet’s picture

@czigor Which modules do you have installed? Could you look for this in your code? Maybe another module is doing something similar.


drupal_add_js('misc/ajax.js'
czigor’s picture

Status: Needs work » Closed (works as designed)

It seems that one of our custom modules had the same drupal_add_js. Changing it to drupal_add_library solved the problem. Thanks!

localnetwork’s picture

Line #34 works for me.