javascript - Saving data into JSON format through Post method -


i using angularjs. want post data in file in json format localhost server i.e. http://localhost:8080/out.json.

how should post method should implement scenario ? or other working example post method able save data in json format helpful.

thanks.

here code :

var app = angular.module('myapp', []);    app.config(['$httpprovider', function($httpprovider) {          $httpprovider.defaults.usexdomain = true;          delete $httpprovider.defaults.headers.common['x-requested-with'];      }  ]);    app.controller('formctrl', function ($scope, $http) {            $scope.data = {          firstname: "default"      };  	$scope.submitform=function($scope, $http) {  		$http.post('someurl', json.stringify(data)).  			success(function(data) {  						console.log(data);  			}).  			error(function(data) {  						console.log(data);  			});  		};  });
<html ng-app="myapp">    <head>    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>    <script src="controller.js"></script>  </head>    <body>    <div ng-controller="formctrl">      <form name="savetemplatedata" action="#">  		first name:    <input type="text" ng-model="data.firstname">   <br/><br/>  		<button type="submit" ng-click='submitform()'>submit</button>  	</form>    </div>  </body>  	  </html>

adding comment answer:

sounds you're sending different domain 1 you're on.. in general can't unless domain accepts such requests.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -