While I try to post the form data in Json format to the server I'm running to some error. My code is as follows.
permissionRequestModel.requestPermission = function () {
if ($("#permissionRequestForm").valid()) {
$.ajax({
url: "",
type: "POST",
data: ko.toJSON(this),
processData:false,
contentType: "application/json",
dataType:"json",
success: function (result) {
alert("Success");
},
error: function (result) {
alert(result.responseText);
}
});
}
else {
}
};
knockout model is as follows
//Model
var permissionRequestModel = {
coNumber: ko.observable(''),
employName: ko.observable(''),
fromDate: ko.observable(''),
toDate: ko.observable(''),
checkFullDay: ko.observable(false),
fromTimeHH: ko.observable(''),
fromTimeMM: ko.observable(''),
toTimeHH: ko.observable(''),
toTimeMM: ko.observable(''),
permissionTypeOne: ko.observable(''),
permissionTypeTwo: ko.observable(''),
approverList: ko.observableArray([]),
reasonLeave: ko.observable('')
};
Read in some places that it might be because Json might be encoded before sending to server but even setting processData couldnt solve it. Please guide.
Error Message
datalook like afterko.toJSON? Do you have any unescaped quotation marks in your JSON? Also, echoing @nemesv, what is the error you get from the error callback?