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!");}
    });
});

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.