I wrote a code that enables me to post an input value (using AngularJS 1.3.5 $http.post) and save it into a db then display it in my html page. To get the new input value after clicking on save I have to refresh the page to display it. I must find a solution without using php and jQuery. I saw an answer Here: changing from $http.post to $xhr.post wasn't possible may be it's caused by the angularJs version I am using. What should I do?
<form ng-submit="save()">
<input ng-model="stack"></input>
<button type="submit">Save</button>
<p>{{stack}}</p>
</form>
$scope.save = function(url, data1) {
/* post to server */
$http({
url : url,
data : {
"stack" : data1
},
method : "POST",
headers : {
'Content-Type' : 'application/json'
}
}).success(function(data, status, headers, config) {
$scope.stack = data.stack;
}).error(function(data, status, headers, config) {
$scope.status = status + ' ' + headers;
});
};
Notice that I am displaying the input value in my html page from the backend.