Passing an array to a server with a signal

How to pass array of strings in javascript to server using SignalR?

I have an array in javascript and would like to do this using a hub function

var selected = new Array(); $('#checkboxes input:checked').each(function () { selected.push($("input").attr('name')); }); 

What type of parameter should the function perform?

+6
source share
1 answer

A hub function can accept an array of strings, a list of strings, etc.

Here's an example hub:

 public class myHub : Hub { public void receiveList(List<String> mylist) { mylist.Add("z"); Caller.returnList(mylist); } } 

Here is an example of a JS part for working with a hub:

 var myHub = $.connection.myHub, myArray = ['a','b','c']; myHub.client.returnList = function(val) { alert(val); // Should echo an array of 'a', 'b', 'c', 'z' } $.connection.hub.start(function() { myHub.server.receiveList(myArray); }); 
+10
source

Source: https://habr.com/ru/post/925434/


All Articles