I am trying to make a post request code -
var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope) {
$scope.data = {};
$scope.reqCalling = function () {
let settings = {
"async": true,
"crossDomain": true,
"url": "myUrl",
"method": "POST",
"headers": {
"content-type": "application/json",
},
"data": JSON.stringify($scope.data),
}
$.ajax(settings).done(function (response) {
console.log("Success",response);
$scope.data = {};
$scope.$apply()
return false;
}).fail(function (error) {
console.log("Failed",error);
// location.reload();
});
}
});
Code of input one field
<input type="email" class="form-control" maxlength="255" placeholder="Email..." ng-model="data.email" name="email">
I have created five fields just like above (firstname, lastname, email, phone, response) these are my input fields.
While making a request I am getting 502 status code.
When I made request from Postman it worked fine... My api is accepting JSON. from postman I passed the body as json
body passed from Postman-
{
"firstname" : "firstname",
"lastname" : "lastname",
"phone" : "0000000000",
"email" : "[email protected]",
"response" : "Testing"
}
I am new to AngularJs Ajax and JQuery I must have did some mistake in the code, Please help me with this.