Opened 14 years ago
Closed 13 years ago
#4756 closed feature (worksforme)
$.ajax() needs a field for opaque data
Reported by: | janosch | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | ajax | Version: | 1.3.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
It would be extremely useful when one could attach a context pointer to a $.ajax() request that would be returned to the callback somehow.
I first thought this could be solved simply by passing a custom option to the $.ajax() function, like so:
jQuery.ajax({
type: "GET", url: "/x.pl", success: succ_callack, dataType: "json", opaque: this,
});
And in the callback:
function succ_callback(data, status) {
var ctx = this.opaque; ... call ctx.something() or so
}
While this works for simple cases, it leads to an infinite loop if the object passed as "opaque" contains a reference to itself (or another object that contains a reference to "opaque" again). This is caused by the recursive call for $.extend() in jquery-1.3.2.js:597 which is started by $.ajax() in :3400.
Any suggestions how to solve this?
Change History (3)
comment:1 Changed 14 years ago by
comment:2 Changed 14 years ago by
That's actually what I thought about aswell, but I'm not familiar with jQuery's internals (e.g. if the jQuery.extend must be a deep extend).
If that proposed patch is the best solution, how about integrating this into the next release and documenting the "opaque" context feature? Is there anything else required for this to be accepted?
comment:3 Changed 13 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
See the context
parameter of the ajax options.
Something like the following should work, I believe.