我有一個JSON源並希望通過發佈請求獲得結果。AngularJS和JSON的代碼問題
當我用逗號測試POSTMAN擴展時,它工作得很好。但是當我用angularJS做這件事時,頁面不斷加載,並且chrome控制檯顯示錯誤。
我的代碼是在這裏:
angular.module('loginApp', []).controller('loginController', function ($scope, $http) {
$scope.userName = '';
$scope.userPass = '';
$scope.output = function() {
var params = JSON.stringify({
username: '******',
password: '******'
});
$http({url: "http://xx.xx.xx.xx/api/user/login.json",
method: 'POST',
data: params,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
}).then(function (response) {
return response;
});
};
});
任何幫助,將不勝感激:)
什麼是在控制檯中的錯誤? –
嘗試不進行字符串化並指定標題,這種類型的請求應該是開箱即用的。 – PiniH
我已經嘗試過沒有stringify()...和頭被指定 – Omer