当我在使用AJAX时,它是非常直接的。
当我用SignalR工作时,我做了以下工作。在服务器上,我的hum方法不返回任何东西(所以我不能更新UI和停止进度条)。相反,我为所有的客户端(包括发送数据的客户端)调用一个类似ThisDataWasChanged的方法。
我不太清楚该怎么做。我的意思是,我当然可以先返回调用中心方法的客户机的数据,然后更新所有其他客户机(以某种方式区分它们),但这似乎是矫枉过正。
你需要做的是在你的Hub类中加入类似以下的内容。
枢纽
public class ProgressBarHub : Hub
{
public void change()
{
// Do some stuff
Clients.Client(Context.ConnectionId).thisDataWasChanged(progressBarObj);
}
}
JS
// Create hub
var hub = $.connection.progressBarHub;
// Connect
$.connection.hub.start().done(function () {
// Start progress bar?
// Create a start progress bar method in the hub and call it
});
hub.client.thisDataWasChanged = function (progressBarObj) {
//Do something to the progress bar with the progressBarObj that we returned
};