Ticket #12874 (closed bug: notabug)
$.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 6 months ago by rwaldron
- Owner set to mt.norbert@…
- Status changed from new to pending
comment:2 Changed 6 months 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 6 months 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 6 months 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 6 months 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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

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.