Answer the question
In order to leave comments, you need to log in
How to pass a POST request with form data and adding a new request parameter in AngularJS?
Hello! There is a need to send a post request with a transition to the page (with a reload, that is, without AJAX), but with the preliminary addition of a new parameter in the request. This function was implemented in jquery with the following code:
function RestoreDefaults()
{
var form= $("form[name=my_form]"),
restore = $(":submit[name=RestoreDefaults]", form);
$("<input />", {type: "hidden", value: restore.val(), name: "RestoreDefaults"}).insertAfter(restore);
form.submit();
}
Answer the question
In order to leave comments, you need to log in
The answer could be more precise if the meaning of the manipulations was clear, but for now something like this:
HTML:
<form name="loginForm" ng-submit="submitForm(loginForm)">
<input type="email" ng-model="user.email">
<input type="password" ng-model="user.password">
<button type="submit">Войти</button>
</form>
.controller('LoginCtrl', function ($scope, $http) {
$scope.user = {};
$scope.user.customField = 'customValue';
$scope.submitForm = function (form) {
$http.post('path/to/your/url', $scope.user)
.success(function (data) {
console.log('data:', data);
})
.error(function (data) {
console.log('Error:', data);
});
};
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question