Here is my JavaScript code
var student = student || {};
student.viewModel = function () {
var self = this;
self.courseCode = ko.observable("");
self.courses = ko.observableArray([
{ "code": "MTH101", "title": "General Mathematics I" },
{ "code": "CHM101", "title": "Introductory Chemistry I" },
{ "code": "PHY101", "title": "General Physics I" },
{ "code": "BIO101", "title": "Introduction to Biology" }
]);
self.removeCourse = function () { self.courses.remove(this); };
self.addCourse = function (data) {
self.courses.push({ code: data, title: "A new Course added " + new Date() });
$('#courseModal').modal('hide');
};
self.save = function() {
$.ajax("test.php", {
data: ko.toJSON({ courses: self.courses }),
type: "get", contentType: "application/json",
success: function(result) { alert(result) }
});
};
};
student.VM = new student.viewModel();
$(document).ready(function () {
ko.applyBindings(student.VM);
});
How do I read the data sent in PHP? json_decode()
only accepts strings and when I also use htmlspecialchars($_GET["courses"])
I get the error undefined index courses. I just want to tell the user the number of courses that was sent to the server.
If it helps, I am testing on localhost using wamp