I wrote a [WebMethod] that return a string that store a serialized object
[WebMethod]
public string doStuffs() {
...
return JavaScriptConvert.SerializeObject(myObj);
// JSON Serializer library is JSON.NET 1.3.1, for MONO
}
When I call the method with a $.post from JQuery:
$.ajax({
type: "POST",
url: "/web/doStuffs",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Do stuffs
}
});
The problem is the response. Here what I get:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://localhost:8080/papi">{
"field1" : "value1", "field2 : "value2", etc etc}</string>
Why JSON response has been encapsulated inside an XML? I can see from HTTP Response header is (wrongly?) set to:
Content-Type text/xml; charset=utf-8
How do I switch the response content type? Thanks.