Reputation: 1025
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.
Upvotes: 1
Views: 4217
Reputation: 755
You should encode your html. it should do this for you:
message=$('<div>').append(message).html()
then you can pass it with $.ajax
Upvotes: 0
Reputation: 6916
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?
Upvotes: 1