JSON编码将viewModel发送到服务器 - 尝试解码时出现500错误?

时间:2015-09-17 01:49:56

标签: json knockout.js

我正在尝试将数据从我的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}
        });
};


}

0 个答案:

没有答案