Naruto Naruto - 1 year ago 65
jQuery Question

Get data from AJAX and send them to SignalR Hub

Good day
I have the following code:

$('#ElementId').click(function () {
type: "POST",
url: "URL",
data: {//DATA }
.done(function (result) {

function FillList(result)
var chat = $.connection.chatHub;

I want to get data form AJAX call and pass them to SignalR but I just cant get it to work. AJAX does its work but when I try to send data to SignaR Hub nothing happens.
For any help thank you in advance


Although the above doesn't work when I call the function on it own without AJAX then it works:

$('#ElementId').click(function () {

This is how the function in question looks in SIgnalR

public void SetResult(string TestJSON)
if (!String.IsNullOrEmpty(TestJSON))
catch (Exception ex)
throw ex


Ted Ted
Answer Source

I see two possible scenarios

  1. result is JSON and not string, so make sure that you are passing a string to SignalR otherwise it will not fire:


  1. If the above doesn't work, the problem is connectivity with your hub. To make sure that there is no datatype mismatch, call the server function with no parameters and see whether it's being hit:



public void SetResult()

After your UPDATE I'm convinced that you are passing JSON to your hub but it's expecting a string... So go with #1

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download