Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#11476 closed bug (duplicate)

Ajax context is lost in deferred

Reported by: thanatica Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2rc1
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by jaubourg)

When using $.ajax as a deferred, the context is lost when the deferred succeeds and does its callback. Consider the following code:

var context = { foo: "bar" };
$.when($.ajax({ url: "...", context: context })).then(function(args) {
  //Where is context gone?

At the point of the comment, there is no trace of the original context object. It seems lost. According to the documentation, it should be in args[0], but args is holding [ returned data, "success", jqXHR ].

Now of course, in this example. it's still accessible due to its scope, but the whole point is to keep it accessible even if it gets out of scope.

Change History (6)

comment:1 Changed 7 years ago by jaubourg

Description: modified (diff)
Resolution: worksforme
Status: newclosed

comment:2 Changed 7 years ago by james

for one argument, but not for more than one.


comment:3 Changed 7 years ago by Rick Waldron

You can only ever have one context, so why would even do that to begin with? I agree that it shouldn't be "undefined", but why would you jump through all of that code? If you want to set an explicit context object, use $.proxy:


comment:4 Changed 7 years ago by jaubourg

Resolution: worksforme
Status: closedreopened

comment:5 Changed 7 years ago by jaubourg

Resolution: duplicate
Status: reopenedclosed

comment:6 Changed 7 years ago by jaubourg

Duplicate of #11749.

Note: See TracTickets for help on using tickets.