-1

Hi have some data to print in the client, the data is dictionary of <string,string> while userCountSpan.textContent = message; return to the screen `object object' and not the data in the dictonary. why?

JavaScript:

 document.addEventListener('DOMContentLoaded', function () {
        function bindConnectionMessage(connection) {
            var messageCallback = function (message) {
                console.log('message' + message);
                if (!message) return;
                var userCountSpan = document.getElementById('users');
                userCountSpan.textContent = message;
            };
            connection.on("updateCount", messageCallback);
            connection.onclose(onConnectionError);
        }

The value in message is the dictonary dataenter image description here

11
  • There is no such thing as "printing" in c#. It depends what next you want to do with the data. Please clarify. Commented Sep 29, 2020 at 7:53
  • Include the response data received by your client in your question. Your server-side screenshot doesn't help at all. Commented Sep 29, 2020 at 7:59
  • @DenisWasilew I want that "message" that has the dictonary will have only the key. so the line ` userCountSpan.textContent = message;` will work Commented Sep 29, 2020 at 7:59
  • @NavahPerkal I'm not sure what it does, but suggested by the name of userCountSpan.textContent = message; don't you just want to pass a count there? Users.Count Commented Sep 29, 2020 at 8:01
  • 1
    Please create a minimal reproducible example Commented Sep 29, 2020 at 8:03

1 Answer 1

-2

Excused me for I don't understand much what you asked. But is this what you want:

foreach(KeyValuePair<string, string> kvp in message)
{
      console.log("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}
Sign up to request clarification or add additional context in comments.

1 Comment

This seems to be a mix of JS and C# so I doubt, that will work ..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.