【发布时间】:2021-08-31 23:39:22
【问题描述】:
我正在尝试发帖请求 代码 -
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();
});
}
});
输入一个字段的代码
<input type="email" class="form-control" maxlength="255" placeholder="Email..." ng-model="data.email" name="email">
我已经像上面一样创建了五个字段(名字、姓氏、电子邮件、电话、回复),这些是我的输入字段。
发出请求时,我收到 502 状态代码。
当我向邮递员提出请求时,它工作正常...... 我的 api 接受 JSON。来自邮递员,我将身体作为 json 传递
从 Postman 传递过来的正文-
{
"firstname" : "firstname",
"lastname" : "lastname",
"phone" : "0000000000",
"email" : "abc@pqr.com",
"response" : "Testing"
}
我是 AngularJs Ajax 和 JQuery 的新手,我一定在代码中犯了一些错误,请帮助我。
【问题讨论】:
标签: javascript jquery angularjs ajax