Opened 3 years ago

Closed 2 years ago

#12126 closed defect (invalid)

xhrGet: ioArgs are not passed on to dojo.Deferred.then

Reported by: Simon Speich Owned by: BryanForbes
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: Changed 3 years ago by bill

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?

comment:2 in reply to: ↑ 1 Changed 3 years ago by Simon Speich

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 3 years ago by Simon Speich

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:4 Changed 3 years ago by fabioginzel

+1

comment:5 Changed 3 years ago by chrism

  • Owner anonymous deleted

comment:6 Changed 3 years ago by kzyp

  • Resolution set to fixed
  • Status changed from new to 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 3 years ago by bill

  • Milestone changed from tbd to 1.7

comment:8 Changed 2 years ago by fredfortier

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 2 years ago by bill

  • Component changed from Core to IO
  • Milestone changed from 1.7 to 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 2 years ago by bill

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:11 Changed 2 years ago by bill

  • Owner set to BryanForbes
  • Status changed from reopened to assigned

comment:12 Changed 2 years ago by psoares

+1

comment:13 Changed 2 years ago by BryanForbes

  • Resolution set to invalid
  • Status changed from assigned to 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.

Note: See TracTickets for help on using tickets.