Bug Tracker

Ticket #12874 (closed bug: notabug)

Opened 2 years ago

Last modified 2 years ago

$.ajax add is not defined

Reported by: mt.norbert@… Owned by: mt.norbert@…
Priority: low Milestone: None
Component: deferred Version: 1.8.2
Keywords: Cc:
Blocking: Blocked by:

Description (last modified by jaubourg) (diff)

Hi,

I am working on a site and I am using backbonejs and requirejs and with r.js I create a bundled js file which contains all my js modularised.

If I make a simple ajax request and I even don't attach any event listener on it I get the following error after I receive the ajax response:

Uncaught ReferenceError: add is not defined
jQuery.Callbacks.self.add.firingLength
jQuery.extend.each
e
jQuery.Callbacks.self.add
jQuery.extend.Deferred.promise.always
jQuery.extend.ajax.jqXHR.statusCode
done
jQuery.support.ajax.jQuery.ajaxTransport.send.callback

I have made some debugging and it seems that the problem is here:

// First, we save the current length
var start = list.length;
(function add( args ) {
        jQuery.each( args, function( _, arg ) {
                var type = jQuery.type( arg );
                if ( type === "function" && ( !options.unique || !self.has( arg ) ) ) {
                        list.push( arg );
                } else if ( arg && arg.length && type !== "string" ) {
                        // Inspect recursively
                        add( arg );
                }
        });
})( arguments );

This is in jquery.js at line 997.

It seems that the recursive call of the add method is not working.

This is how I made the ajax request:

$.ajax(baseUrl+'query',{
        data:form.serialize(),
        dataType: 'json',
        type: 'post'
});

Change History

comment:1 Changed 2 years ago by rwaldron

  • Owner set to mt.norbert@…
  • Status changed from new to pending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!

Additionally, be sure to test against the "jQuery (edge)" version to ensure the issue still exists. To get you started, use this boilerplate:  http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to begin.

comment:2 Changed 2 years ago by dmethvin

  • Owner mt.norbert@… deleted
  • Status changed from pending to new

 https://github.com/jquery/jquery/pull/1028

I'm not clear on how this is happening. The parens around the function shouldn't create a new scope? Is this something the r.js optimizer is transforming within the code?

comment:3 Changed 2 years ago by dmethvin

  • Owner set to mt.norbert@…
  • Priority changed from undecided to low
  • Status changed from new to pending
  • Component changed from unfiled to deferred

comment:4 Changed 2 years ago by jaubourg

  • Description modified (diff)

Does this work without using r.js? In which case it's a bug in r.js, not jQuery.

comment:5 Changed 2 years ago by dmethvin

  • Status changed from pending to closed
  • Resolution set to notabug

We haven't received replies on this, and it's not clear how this can be a bug in jQuery. Please reply with some technical details if this still needs to be addressed. If r.js is changing the code it sounds like the transformation is being done wrong.

comment:6 Changed 2 years ago by mt.norbert@…

Sorry, I don't really have time to create a use case. I think it's better if you close this and if I will create a use case I will write a new comment. Sorry again.

Note: See TracTickets for help on using tickets.