控制器
).controller('LoginController',
[
'$scope',
'dataService',
'$location',
'$window',
function ($scope, dataService, $location,$window){
$scope.check_login=function($event,userID,passwd)
{
dataService.login(userID,passwd).then
(
function (response){
$scope.loginCount = response.rowCount + 'account Record';
$scope.loginConfirm = response.data;
console.log(response.data);
},
function (err) {
$scope.status = 'unable to connect to data' + err;
});
// $scope.reloadRoute = function () {
// $location.path('/#');
// $window.location.reload()
// }//end of reload route fnction
}//end of function check_login
}
]Services.js
this.login = function (userID, passwd) {
var defer = $q.defer(),
data = {
username: userID,
password: passwd
};
$http.post(urlBase, {
params: data,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
cache: true
})
. // notice the dot to start the chain to success()
success(function (response) {
defer.resolve({
data: response.login.Result, // create data property with value from response
rowCount: response.login.RowCount // create rowCount property with value from response
});
})
. // another dot to chain to error()
error(function (err) {
defer.reject(err);
});
// the call to getCourses returns this promise which is fulfilled
// by the .get method .success or .failure
return defer.promise;
};index.php
if (isset($_POST['username']) && isset($_POST['password'])) {
$useremail = $_POST['username'];
$password = $_POST['password'];
$service = new FilmsService();
$result = $service->login($useremail, $password);
echo $result;
} else {
echo "Cant Find The Data";
}目前,我得到了3个文件名:控制器、 service.js 和index.php,service.js是u将数据传递给php端,但当我尝试在php端获取用户名和密码E 212时,将是error.Cant get E 113用户名E 214和E 115密码E 216。
如何解决这个问题?是我的代码错误吗?
发布于 2016-03-18 16:52:28
用这个代替您的$http.post:
$http({
method: 'POST',
url: urlBase,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: data
});https://stackoverflow.com/questions/36089654
复制相似问题