0
Ionic Frameworkを使用してハイブリッドアプリケーションを開発しています。 $ http Restful Webサービスを使用してサーバーにデータをPOSTし、サーバーから応答を取得します。私はブラウザでそれをテストすると、うまく動作し、私はサーブからデータを取得することができました。しかし、私はそれを私のアンドロイドデバイスでテストすると、全く動作しません。以下は私のコードです。
Angularjsコード
$scope.validateBorrower = function(){
employeeNumber = $scope.assetBorrowing.employeeNumber;
employeeName = $scope.assetBorrowing.employeeName;
employeeDeparment = $scope.assetBorrowing.employeeDepartment;
if(employeeNumber == null && employeeName == null){
alert("Please Enter Employee Number or Employee Name");
}else{
$http({
url: "http://131.4.44.69/php3/validateBorrower.php",
method: "POST",
data: {
'employeeNumber': employeeNumber,
'employeeName' : employeeName
},
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function(response) {
alert("Valid Employee");
$scope.assetBorrowing.employeeNumber = response[0].employeeNumber;
$scope.assetBorrowing.employeeName = response[0].employeeName;
$scope.assetBorrowing.employeeDepartment = response[0].employeeDepartment;
$scope.borrowbtn = false;
}).error(function(response) {
alert("error");
});
alert(employeeNumber);
}
}
PHPバックエンドのコード
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: false");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
header('P3P: CP="CAO PSA OUR"');
header("Content-Type: application/json; charset=utf-8");
$postdata = file_get_contents("php://input");
$employeeRequest = json_decode($postdata, true);
@$employeeNumber = $employeeRequest['employeeNumber'];
@$employeeName = $employeeRequest['employeeName'];
if(empty($employeeNumber)){
@$employeeName = $employeeRequest['employeeName'];
}else{
@$employeeName = "";
}
$db_host = "localhost";
$db_user = "jack";
$db_password = "1234";
$db_database = "daikin_asset_management";
$conn = new mysqli($db_host, $db_user, $db_password, $db_database);
if($conn->connect_error){
echo "Connection Problem";
}
if(empty($employeeNumber) && empty($employeeName)){
echo "Error";
}else{
$getUserQuery = "SELECT * FROM xpouser WHERE (username='$employeeName') OR (employee_no = '$employeeNumber') ";
$getUserRetval = $conn->query($getUserQuery);
$userRow = mysqli_fetch_array($getUserRetval);
$employeeName = $userRow['username'];
$employeeNumber = $userRow['employee_no'];
$employeeDepartment = $userRow['department'];
$_arr = array();
$array = array(
'employeeNumber' => $employeeNumber,
'employeeName' => $employeeName,
'employeeDepartment' => $employeeDepartment
);
$jsonObjectChannel = json_encode($array);
$jsonObjectChannel = "[" . $jsonObjectChannel . "]";
echo $jsonObjectChannel;
}
?>