Bug Tracker

Modify

Ticket #11476 (closed bug: duplicate)

Opened 14 months ago

Last modified 10 months ago

Ajax context is lost in deferred

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

Description (last modified by jaubourg) (diff)

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

comment:1 Changed 14 months ago by jaubourg

  • Status changed from new to closed
  • Resolution set to worksforme
  • Description modified (diff)

comment:2 Changed 10 months ago by james

for one argument, but not for more than one.

 http://jsfiddle.net/E5rqx/1/

comment:3 Changed 10 months ago by rwaldron

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:

 http://jsfiddle.net/rwaldron/E5rqx/3/

comment:4 Changed 10 months ago by jaubourg

  • Status changed from closed to reopened
  • Resolution worksforme deleted

comment:5 Changed 10 months ago by jaubourg

  • Status changed from reopened to closed
  • Resolution set to duplicate

comment:6 Changed 10 months ago by jaubourg

Duplicate of #11749.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.