Ticket #4851 (closed bug: fixed)
Inside ajax callback function (success, error), 'this' context does not retain 'data' property consistently/correctly
| Reported by: | rtaylor | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.4 |
| Component: | ajax | Version: | 1.3.2 |
| Keywords: | ajax callback | Cc: | |
| Blocking: | Blocked by: |
Description
Inside ajax callback function (success, error), 'this' context does not retain 'data' property consistently/correctly.
USING A GET:
jQuery.ajax({ url: ' http://localhost/example', data: {
myValue1: 'foo', myValue1: 'bar'
}, success: function(data, textStatus) {
this.data == null BUG IS HERE this.success == function() as expected
} )
USING A POST:
jQuery.ajax({ url: ' http://localhost/example', type: 'POST' data: {
myValue1: 'foo', myValue1: 'bar'
}, success: function(data, textStatus) {
this.data == 'myValue1=foo&myValue2=bar'; this.success == function() as expected
} )
My perspective is that if 'data' as passed in options to jQuery.ajax is N/V pairs, as is the case with this example, the 'data' property on the call back context should be that very same object, regardless as to GET or POST, also not URL encoded etc.
Would be very convenient and helpful if it worked as such.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Also, doc thusly reads incorrectly:
http://docs.jquery.com/Ajax/jQuery.ajax.......
function (data, textStatus) {
}