I just recently tried learning javascript and I want to make a website that uses JSON files as storage. So far I have been to make the GET method work:
$.ajax({
type: 'GET',
url: 'Projects/Sample/data.json',
success: function(data) {
console.log("I have friends!", data);
}
});
Since I am learning from this site http://rest.learncode.academy/, I also tried using its post method:
$.ajax({
type: 'POST',
url: 'Projects/Sample/data.json',
data: {name: 'Billy Bob', age: 27},
success: function(data) {
console.log("Friend added!", data); //the new item is returned with an ID
}
});
This code works if I use the website's json http://rest.learncode.academy/api/johnbob/friends. But when I try to use my JSON file located in my web server, new data don't seem to be added. I am using XAMPP as my web server.