这是我的工作代码:
$(function() {
$.connection.hub.url = 'sampleUrl';
$.connection.hub.start().done(function() {
var uid = settingInvoiceUID;
if (uid !== '')
$.connection.notifyHub.server.registerInHub(uid);
});
$.connection.notifyHub;
$.connection.notifyHub.client.updateClient = function(gInfo) {
alret('blah blah blah');
}
});
我想以这种方式使用它,一切都会正常工作,只是服务器无法updateClient在此代码中调用此方法:
$("[id*='qrCodeImage']").click(function() {
var postUrl = '/sample.aspx/SetAsScanned';
var postedData = "{data: '" + settingInvoiceUID + "'}";
$.ajax({
type: 'POST',
url: postUrl,
dataType: 'json',
data: postedData,
contentType: "application/json; charset=utf-8",
success: function(data) {
var result = JSON.parse(data.d);
if (result.IsSuccess) {
$.connection.hub.url = 'sampleUrl';
$.connection.hub.start().done(function() {
var uid = settingInvoiceUID;
if (uid !== '')
$.connection.notifyHub.server.registerInHub(uid);
});
$.connection.notifyHub;
$.connection.notifyHub.client.updateClient = function(gInfo) {
alret(gInfo);
}
});
});
是否可以在回调中设置所有 SignalR 代码,包括连接和集线器注册以及 clientMethod?
智慧大石
相关分类