1

I have the following call in my app:

...
var message = "<label style='font-weight: bold; font-size: 14px; color: Gray;'>" + currentPlayerName + "</label>:  ";
$.ajax({
        url: "/Game/SendMessage",
        type: "POST",
        data: "matchID=" + matchID + "&message=" + message,
        dataType: "json",
        success: function (result) {
            if (result.Message != null) {
                var div_MessagePanel = $("#div_MessagePanel");

                $("#div_MessagePanel").append(result.Message + "<br />");
            }

            checkForUpdate();
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert("Error occured 1!");

            sendMessage(message);
        }
    }); 

When I call this function it always drops an error. I think there is a problem with the data that I want to send back to the server. Any help is appreciated. Thanks.

3 Answers 3

1

I think it would be useful to see what you're actually trying to send. Content type should be selected according to your data.

Here is a small quote from the jQuery ajax API documentation.

The data option can contain either a query string of the form key1=value1&key2=value2, or a map of the form {key1: 'value1', key2: 'value2'}. If the latter form is used, the data is converted into a query string using jQuery.param() before it is sent. This processing can be circumvented by setting processData to false. The processing might be undesirable if we wish to send an XML object to the server; in this case, we would also want to change the contentType option from application/x-www-form-urlencoded to a more appropriate MIME type.

Maybe you could also tell us what errorThrown contains?

Sign up to request clarification or add additional context in comments.

Comments

0

Try using encodeURI to encode your html string before being passed to your ajax call.

Comments

0

You should encode your html. it should do this for you:

message=$('<div>').append(message).html()

then you can pass it with $.ajax

Comments

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.