Currently, I am in the process of developing a phonegap application using AngularJS that relies on a .json file to store an array of entries. The main goal I am aiming for is to enable users to mark specific entries as favorites and then utilize that data elsewhere (such as displaying only favorites on another page). This is my first venture into web development, and I must admit that I am quite new to various web technologies like AngularJS, JSON, PhoneGap, etc. However, despite my limited experience, I have decided to forge ahead with this project.
In my attempts to save this data, I have explored options such as IndexedDB, WebSQL DB, and WebStorage but found them to be somewhat complex when integrated with PhoneGap. Therefore, I am now focusing on modifying a field within the .json file and saving the updated file instead.
Although JavaScript cannot directly write files, I experimented with sending the file via POST method as a workaround. Below is the snippet of code for the function I am currently using:
$scope.save = function() {
$http({
method: 'POST',
url: 'data.json',
data: $scope.json_data
}).success(function(response) {
addLog("Success message.");
}).error(function(response){
addLog("Error message.");
});
}
I am hesitant to delve into extensive server-side code management since I am unsure if PhoneGap can handle it. I also lack the knowledge of where to commence such an implementation. Perhaps there is a simpler solution, like utilizing transformRequest or some other method to save the json file. Any suggestions on how to proceed? Should I attempt to save the modified .json file through some special code, or would it be more prudent to reconsider my approach entirely?
Your insights and guidance are greatly appreciated!