Side navigation
#11852 closed feature (notabug)
Opened June 03, 2012 09:02PM UTC
Closed November 24, 2012 10:34PM UTC
Last modified November 27, 2012 05:40PM UTC
Use context parameter in .load
Reported by: | anonymous | Owned by: | jaubourg |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | ajax | Version: | 1.7.2 |
Keywords: | Cc: | jaubourg | |
Blocked by: | Blocking: |
Description
I know this is very trivial, but it is an enhancement never the less.
The .load
function (ajax) assigns this
to self
on line 7159.
It would be better to use the context parameter of the $.ajax
function as follows and then omitting the assignment to self
.
#!js jQuery.ajax({ url: url, type: type, dataType: "html", data: params, context: this, // Complete callback (responseText is used internally) complete: function( jqXHR, status, responseText ) { // Store the response as specified by the jqXHR object responseText = jqXHR.responseText; // If successful, inject the HTML into all the matched elements if ( jqXHR.isResolved() ) { // #4825: Get the actual response in case // a dataFilter is present in ajaxSettings jqXHR.done(function( r ) { responseText = r; }); // See if a selector was specified // (Target element is this - coming from context) this.html( selector ? // Create a dummy div to hold the results jQuery("<div>") // inject the contents of the document in, removing the scripts // to avoid any 'Permission Denied' errors in IE .append(responseText.replace(rscript, "")) // Locate the specified elements .find(selector) : // If not, just inject the full result responseText ); } if ( callback ) { this.each( callback, [ responseText, status, jqXHR ] ); } } });
Patch: http://pastebin.com/A5cYSQKV
In case you are interested where this ''could'' have any relevance see this: http://stackoverflow.com/a/10864327/1238764
Attachments (0)
Change History (8)
Changed June 23, 2012 02:29PM UTC by comment:1
cc: | → jaubourg |
---|---|
component: | unfiled → ajax |
milestone: | None → 1.8 |
priority: | undecided → low |
status: | new → open |
Changed June 25, 2012 04:28PM UTC by comment:2
owner: | → jaubourg |
---|---|
status: | open → assigned |
Changed August 10, 2012 05:55PM UTC by comment:3
milestone: | 1.8 → 1.8.1 |
---|
Changed August 27, 2012 02:04PM UTC by comment:4
milestone: | 1.8.1 → 1.9 |
---|
Changed September 09, 2012 01:10AM UTC by comment:5
type: | enhancement → feature |
---|
Bulk change from enhancement to feature.
Changed November 24, 2012 10:34PM UTC by comment:6
resolution: | → notabug |
---|---|
status: | assigned → closed |
Since this would change the callbackContext of the global events fired by $.ajax
I think it's better not to land it just in case some code would be confused by the change.
https://github.com/jquery/jquery/blob/67df705bf5205fa075ba6ceee2d7fd4763894a16/src/ajax.js#L358
Changed November 24, 2012 10:51PM UTC by comment:7
Damn, it's been 6 months and I didn't answer to this one? Oo
Totally agree with dmethvin on not breaking backward compatibility here.
Changed November 27, 2012 05:40PM UTC by comment:8
milestone: | 1.9 → None |
---|
Seems like a good idea to me ... jaubourg?