1

I am using Eclipse Kepler IDE. I am unable to write the data in the local JSON file at the folder location JSON/a.json.

Here is my code given below.

$("#submitDetails").click(function(){
    var newJSONData = {};
    //alert("Function called");
    projectID=$("#projectID").val();
    managerID=$("#managerID").val();
    pocId=$("#pocId").val();
    comment=$("#comment").val();


    newJSONData = [{
        "Project" :projectID,
        "ManagerID" :managerID,
        "POC" :pocId,
        "Comment":comment
    }];


    $.ajax
    ({
        type: 'POST',
        url: 'JSON/a.json',
        data: newJSONData,
        success: function () {alert("Project Submitted!"); },
        failure: function() {alert("Error in project submission!");}
    });
});
Prateek
  • 135
  • 3
  • 15

1 Answers1

7

You can't write to the local file system directly from browser-based JavaScript code. Consider the implications if you could. :-)

Instead, you have to run a web server locally and have a server-side resource to receive the data, authenticate and authorize the request (e.g., make sure its okay to write the file), and write it out. Then post the data to the URL of that server-side resource on the local server.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875