Reputation: 1
Is there any global listeners we can add for d3.xhr calls like what we have in ExtJS. Ext.Ajax.on("beforerequest", function(conn, options, eOpts){)};
I tried using 'on' as specified in https://github.com/mbostock/d3/wiki/Requests#on
while trying
d3.xhr.on("beforesend", function(request){
console.log("inside on");
});
I am getting following error. Uncaught TypeError: d3.xhr.on is not a function
while trying below code
d3.xhr(url, callback).on("beforesend", function(request){
console.log("inside on");
});
following error is thrown. Uncaught TypeError: Cannot read property 'on' of undefined
Do I have to do anything special to enable the listeners ?
Thanks in advance.
Upvotes: 0
Views: 210
Reputation: 109242
You don't need to do anything special, but you have to use the long form with .get()
to use the .on()
handlers. That is, you can't provide the callback function as the second argument to d3.xhr()
:
d3.xhr("http://www.example.com") // note no callback function!
.on("beforesend", function(request){
console.log("inside on");
})
.get(function(error, data) {
console.log(error, data);
});
Complete demo here. Also see this example.
Upvotes: 1