Opened 9 years ago
Closed 8 years ago
#12126 closed defect (invalid)
xhrGet: ioArgs are not passed on to dojo.Deferred.then
Reported by: | Simon Speich | Owned by: | Bryan Forbes |
---|---|---|---|
Priority: | high | Milestone: | 1.8 |
Component: | IO | Version: | 1.5 |
Keywords: | xhrGet, dojo.Deferred, then | Cc: | |
Blocked By: | Blocking: |
Description
If I use the returned deferred instead of the load/error callbacks in a xhrGet(), the ioArgs are not passed to the dojo.Deferred.then(), e.g.:
var dfd = dojo.xhrGet({ ... load: function(result, ioArgs) { console.log('load', result, ioArgs); }, error: function(err, ioArgs) { console.log('error', err, ioArgs); } }); // is not the same as: dfd.then(function(result, ioArgs) { console.log('then', result, ioArgs); // ioArgs is undefined }, function(err, ioArgs) { console.log('then', err, ioArgs); // ioArgs is undefined });
Change History (13)
comment:1 follow-up: 2 Changed 9 years ago by
comment:2 Changed 9 years ago by
Replying to bill:
Does ioArgs have information besides what the app passed into dojo.xhrGet() in the first place?
Yes, I would like to access the ioArgs.xhr object
comment:3 Changed 9 years ago by
Especially if you would like to pass back a custom (json) error message in the http body, then you would need access ioArgs.xhr.responseText
comment:5 Changed 9 years ago by
Owner: | anonymous deleted |
---|
comment:6 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixed in [25095]. Note that that responseText and status have always been available on the error object. The only things that were not previously available that is now available are response headers.
comment:7 Changed 9 years ago by
Milestone: | tbd → 1.7 |
---|
comment:8 Changed 8 years ago by
I see that this ticket is closed, but I am getting the same issue with Dojo 1.7.1. Is this still an open issue in 1.7.1? If not, what could I be missing?
var workItemDef = xhr.get( {
url : this._workplaceXtUrl + "/P8BPMREST/p8/bpm/v1/queues/" + queueName + "/stepelements/" + workObjectNumber, handleAs : "json"
}).then(function(data, ioargs) {
self.util.debug("printing the data object", [data, ioargs <--- FireBug? tells me that ioargs is 'undefined']);
comment:9 Changed 8 years ago by
Component: | Core → IO |
---|---|
Milestone: | 1.7 → 1.8 |
I don't see how [25095] is related to this ticket at all. Kris' comment though is talking about the error callback (when the XHR fails), not the success callback. As I said above the success callback only gets one argument, so it's just a question of what that argument is. I think Bryan's work on dojo/request will handle this.
comment:10 Changed 8 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:11 Changed 8 years ago by
Owner: | set to Bryan Forbes |
---|---|
Status: | reopened → assigned |
comment:13 Changed 8 years ago by
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
The requested functionality is already provided, albeit in a different place. If you use the return value from dojo/_base/xhr
, it will have an
ioArgs
property on it. This is the same as the second argument to
load
and
error
:
var def = xhr.get({ url: "foo" }); def.then(function(text){ console.log("Printing the data object", def.ioArgs); });
Remember, however, that the return value of a chained then
call will not be a deferred, but a promise. This means that the following will not work because of how Deferreds/Promises? work:
var def = xhr.get({ url: "foo" }).then(function(text){ console.log("Printing the data object", def.ioArgs); });
def
ends up being a promise because the Deferred from
xhr.get
has been chained off of.
A Deferred represents a single (future) value, so (IIUC) it's not possible to pass a second parameter to then()'s callback function. Of course the Deferred's value could be an array like [result, ioArgs], but that would break backwards compatibility.
Does ioArgs have information besides what the app passed into dojo.xhrGet() in the first place?