简体   繁体   中英

How to send data back into SignalR Hub

is it possible to directly send data back into SignalR Hub from the front end JS/JQ (im working with lists and monitoring). For example take textbox input and plug it back into a list on the back end of the server? If any one can drop that 1 liner execution line would be also appreciated thanks.

Yes, I assume you have something in your javascript like:

var chat = $.connection.signalRPushEvents;

Then later on you can do this in Javascript:

chat.server.BroadcastData(a, b, c);

Then the class you're extending Microsoft.AspNet.SignalR.Hub with should contain a method with that signature which is what that Javascript will effectively be calling.

public void BroadcastData(int a, string b, double c)
{
    // Do something with Clients or whatever here
}

Figured it out. If anyone has a better solution, please reply as I am new to this API.

hub.invoke('HubMethodName', 'DOM or Value for Insert');

I am sure there is a possible way to send the message back using a callback in JS once the message is received. Have you tried creating a callback function for each time a message is sent, and adding what you receive in the callback(ie the message) to the list you may want to put on the server?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM