2

I'm very new in AngularJS. I want to post registration data to a json file. Post request is working correctly,but data is not writing to file. I can't understand that position. Is there something wrong with my post request code? And how can I fix that? Thanks!

 var regModel = {
    FirstName: 'Someone',
    LastName: 'Somebody',
    Address: 'somewhere',
    Email: '[email protected]'
};

$scope.insertUser = function () {
    $http.post('../DB/users.json', regModel).
        success(function(data, status, headers, config) {
            // this callback will be called asynchronously
            // when the response is available
        }).
        error(function(data, status, headers, config) {
            // called asynchronously if an error occurs
            // or server returns response with an error status.
        });
}

2 Answers 2

1

With your current setup, your post request will have your regModel object in the content of your request. On the server side, you can get the body or content and then write it to file.

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

2 Comments

It means I can't write to a file in client side, yeah?
I am unaware of any known way on the client side.
1

You cannot write directly on a file located on the server from the client. As willwin.w said, your data regData should be transmitted with the request. But you will have to direct your ajax request toward a server side script like PHP, ASP, etc. This script will then have to get the data passed in the ajax request and write them in a file or a database.

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.