#11852 closed feature (notabug)
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
.
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
Change History (8)
comment:1 Changed 11 years ago by
Cc: | jaubourg added |
---|---|
Component: | unfiled → ajax |
Milestone: | None → 1.8 |
Priority: | undecided → low |
Status: | new → open |
comment:2 Changed 11 years ago by
Owner: | set to jaubourg |
---|---|
Status: | open → assigned |
comment:3 Changed 10 years ago by
Milestone: | 1.8 → 1.8.1 |
---|
comment:4 Changed 10 years ago by
Milestone: | 1.8.1 → 1.9 |
---|
comment:5 Changed 10 years ago by
Type: | enhancement → feature |
---|
Bulk change from enhancement to feature.
comment:6 Changed 10 years ago by
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
comment:7 Changed 10 years ago by
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.
comment:8 Changed 10 years ago by
Milestone: | 1.9 → None |
---|
Seems like a good idea to me ... jaubourg?