javascript - AngularJS $http.post succeeds but doesn't save the data -


i'm trying save array json file that's located on webserver. response successful when open json it's empty.

i've tried create json object of own manually yielded same results.

here's process:

app.controller('bookcontroller', ['$window', '$http', function ($window, $http) {  this.contacts = [];    this.exportcontacts = function(contacts){      $http({          method: "post",          url: '/data/contacts.json',          headers: { 'content-type': 'application/json' },          data: contacts      }).then(function goodcall(){          $window.alert("save done!");      }, function badcall(){          $window.alert("failed save error! error: " + $http.status);      });  };  }]);

i fill array inputs via form:

<form name="addcont" ng-show="showform" ng-controller="contactcontroller contactctrl" ng-submit="contactctrl.addcontact(addcont, bookctrl.contacts)" novalidate>  <label>      first name:      <input name="fname" type="text" required ng-pattern="/^(\d)+$/" ng-model="contactctrl.contact.firstname"></input>      <span style="color:red" ng-show="addcont.fname.$dirty && addcont.fname.$invalid">          <span ng-show="addcont.fname.$error.required">first name required.</span>          <span ng-show="addcont.fname.$error.pattern">first name must contain letters only!</span>      </span>  </label>  <label>      last name:      <input name="lname" type="text" ng-pattern="/^(\d)+$/" ng-model="contactctrl.contact.lastname"></input>      <span style="color:red" ng-show="addcont.lname.$dirty && addcont.lname.$invalid">          <span ng-show="addcont.lname.$error.pattern">last name must contain letters only!</span>      </span>  </label>  <label>      phone number:      <input name="phone" type="tel" required ng-model="contactctrl.contact.phone" ng-minlength="9" ng-maxlength="10" ng-pattern="/^(\d)+$/"></input>      <span style="color:red" ng-show="addcont.phone.$dirty && addcont.phone.$invalid">          <span ng-show="addcont.phone.$error.minlength">phone number short!</span>          <span ng-show="addcont.phone.$error.maxlength">phone number long!</span>          <span ng-show="addcont.phone.$error.required">phone number required!</span>          <span ng-show="addcont.phone.$error.pattern">must not contain letters!</span>      </span>  </label>  <label>      notes:      <input name="notes" type="text" ng-model="contactctrl.contact.notes"></input>  </label>  <input type="submit" value="submit" ng-disabled="addcont.fname.$invalid || addcont.lname.$invalid || addcont.phone.$invalid" />  </form>

so array should somethings this:

[{     firstname: "tim",     lastname: "asdxc",     notes: "asdasd",     phone: "0532753940" },{     firstname: "timz",     lastname: "asdasd",     notes: "asdasd",     phone: "123123123" }] 

do somehow need parse array before sending it?

as far understand code, missing important peace. need restful service on server. otherwise not able save/write files on server.

i recommend familiar node , may express start.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -