是否可以将这样的字符串传递给 WCF 服务:
self.savePreferences = function(callback) {
$.ajax({
url: "services/Foo.svc/SavePreferences",
type: 'POST',
timeout: 3000,
data: ko.mapping.toJSON(self.user().preferences),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (result) {
if (result) {
alert("data saved " + result);
} else {
//todo, send server email alert
alert("Something went wrong. We will look into it.");
}
}
});
}
在这种情况下,我的服务中的 jsonPreferences 总是为 null
[OperationContract]
[WebInvoke(
Method = "POST",
RequestFormat = WebMessageFormat.Json)]
string SavePreferences(string jsonPreferences);
还是我需要这样做:
数据:JSON.stringify(ko.mapping.toJSON(self.user().preferences))