3

i am getting this error Error: Failed to invoke 'MoveLobbyCard' due to an error on the server. when trying to perform an action in lobby my js code:

"use strict";

var connection = new signalR.HubConnectionBuilder().withUrl("/hub").build();

connection.start().then(function () {
}).catch(function (err) {
    return console.error(err.toString());
});

connection.on("UserConnected", function (ConnectionId) {
    $("#userlist").append($("<li>").text(ConnectionId + "has joined"));
    var lobbyID = $('#lobbyID').text();
    connection.invoke("JoinLobby", lobbyID).catch(function (err) {
        return console.error(err.toString());
    });
});

connection.on("CardMoved", function (id) {
    $('#'+id).addClass("moved");
});


$('.card').on("click", function (){
    var id = $(this).attr("id");
    connection.invoke("MoveLobbyCard",id,lobbyID).catch(function (err) {
        return console.error(err.toString());
    });
});

it does add to groups but i have no idea whats causing the error

Turqay Umudzade
  • 171
  • 2
  • 13

2 Answers2

3

For me the error was caused by a method signature on the hub expecting an integer but javascript providing it (a number) as a string. I changed the hub to accept a string and parsed it to an integer before use and it was all good.

0

the error was caused due var id not being a global variable so instead of the id it took the entire span.

Turqay Umudzade
  • 171
  • 2
  • 13