dojo.xhr
is deprecated in favor of dojo/request/xhr
, the documentation for which you can find here.
You can still use dojo/aspect
as in the example. I've created a fiddle that does just that. The relevant code follows.
require([
'dojo/request/xhr',
'dojo/aspect'
], function(xhr, aspect) {
aspect.before(xhr, 'post', function() {
console.log('before POST');
});
// use xhr.post here...
});
If you still want to cover legacy code that uses dojo.xhr
, you can extract the function you use in aspect
and pass it to both objects:
function beforeXhr() {
// ...
}
aspect.before(dojo, 'xhr', beforeXhr);
aspect.before(xhr, 'post', beforeXhr);
I haven't figured out how to use dojo/aspect
on functions that are returned to the require
callback, which means you'd have to repeat the aspect
calls for 'GET', 'PUT', 'DELETE', etc. If anyone knows how to use aspect
with a function object as in this example, I'd love to know.