我们无法在 Angular js 中使用 Web api2 方法
module.exports = function ($http, utils) {
var self = this;
self.login = function (credentials) {
var config = {
headers: {
//'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
'Content-Type': 'application/json'
}
};
return $http.post(utils.apiUrl('admin/login'), credentials, config);
};
};
您实际上正在接触服务器,但没有读取响应。由于 $http 返回一个承诺,正确的方法是:
$http.post(utils.apiUrl('admin/login', credentials, config).then(function(response) {
return response;
});