我正在尝试将数据从我的viewModel发送到服务器作为JSON
这是我的视图模型,我看不出它失败的原因 - JSON在JSON测试站点上传递。
服务器在第二次尝试运行json_decode时仍然抛出500错误 - 这让我觉得数据无效JSON - 撕掉我的头发!!!
任何帮助都将不胜感激!!
var companyInfoViewModel = function (data) {
var self = this;
data = data || {};
self.data = ko.observable(data);
self.id = ko.observable(self.data().id || '');
self.companyName = ko.observable(self.data().companyName || '');
self.address1 = ko.observable(data.address1 || "");
self.address2 = ko.observable(data.address2 || "");
self.town = ko.observable(data.town || "");
self.postcode = ko.observable(data.postcode || "");
self.mainNumber = ko.observable(data.mainNumber || "");
self.mainFax = ko.observable(data.mainFax || "");
self.mainEmail = ko.observable(data.mainEmail || "");
self.startDate = ko.observable(data.startDate || "");
self.uniqueTaxpayersReference = ko.observable(data.uniqueTaxpayersReference || "");
self.defaultTaxRate = ko.observable(data.defaultTaxRate || "");
self.fullAddress = ko.computed(function () {
return self.address1() + ", " + self.address2() + ", " + self.town() + ", " + self.postcode();
}, this);
save = function (){
$.ajax({
type: "POST",
url: rootURL + "clients/client",
data: ko.toJSON(self),
dataType: "json",
success: function(data){console.log(data)}
//function(data){window.location.href = site_URL + "clients/client/id/" + data}
});
};
}