#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 )
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 11 years ago by
Description: | modified (diff) |
---|---|
Resolution: | → worksforme |
Status: | new → closed |
comment:3 Changed 11 years ago by
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 11 years ago by
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
comment:5 Changed 11 years ago by
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
Works for me: http://jsfiddle.net/kQMyz/