I have a hub server method called with signalr many times. I know i can do:
hub.server.method().done(function(data){
//my_code
}
but is there any way I can set a 'default' done() function so I don't have to repeat it every time I call that method?
Create a function in your *.js file like this
function doSomething(){
hub.server.method().done(function(data){
//my_code
}
};
And then call doSomething instead of
hub.server.method().done(function(data){
//my_code
}
Edited:
If you want to add a function to the server object you can do:
hub.server.myDecoratedBehavior= function() {
if (connected) {
this.originalBehavior().done(function () {
console.log("Chat window was cleared");
});
}
};
var onDone = function(data) {
// code
};
hub.server.method1().done(onDone);
hub.server.method2().done(onDone);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.