The default encoding used by $.ajax() is application/x-www-form-urlencoded
.
To fix this, control the encoding and tell the other end exactly what encoding was used. Note the explicit stringification of the object, and the explicit encoding of text/json
for the contentType
.
var data = {
fileName: self.fileName(),
fileDesc: self.fileDesc(),
};
$.ajax({
url: "Fx.svc/WriteUploadItem",
data: JSON.stringify(data),
contentType: "text/json"
}).done(function (result) {
//implementation
}).error(function (err) {
//handle error
});
The content type encoding you specify will also be used for the return value unless you specify a different encoding. Usually it's very satisfactory to get JSON back since $.ajax() will magically parse it into the result object, but when you are returning a simple type such as an int
, you'll need to specify a return encoding of text/plain using the dataType
parameter.
$.ajax({
url: "Fx.svc/WriteUploadItem",
data: JSON.stringify(data),
contentType: "text/json",
dataType: "text/plain"
}).done(function (result) {
//implementation
}).error(function (err) {
//handle error
});