在尝试使用angularjs和php进行登录时,我在JSON的位置0错误中获得了这个意外的令牌u。我不知道它意味着什么或如何解决它,这就是我正在做的事情。
.controller('LoginCtrl', function($scope,$http) {
$scope.login=function(){
var version = "1.4.0";
$http({
url: 'http://localhost/php/prueba.php',
method:'POST',
data: {
usuario: $scope.usuario,
password:$scope.password,
version:version
},
headers:{
'Contect-Type':'application/x-www-form-urlencoded'
}
}).then(function(response){
console.log(response);
})
}
这是我的.js文件,在我的PHP中,这就是我所拥有的
<?php
//error_reporting(E_ALL);
//display_errors(1);
header('Access-Control-Allow-Origin');
header('Content-Type: application/json');
session_start();
$postdata=file_get_contents("php://input");
$request=json_decode($postdata);
$usuario = $request->usuario;
$password = $request->password;
$version = $request->version;
/*$angular_http_params =
(array)json_decode(trim(file_get_contents('php://input')));
$usuario = $angular_http_params['usuario'];
$password = $angular_http_params['password'];
$version = $angular_http_params['version'];
*/
echo "usuario " . $usuario;
echo " password " . $password;
echo " version " . $version;
?>
所以如果有人可以帮我解决,我会很高兴的