2015-10-06 82 views
1

嗨,大家好,我有我的PHP文件是这样的:离子登录使用PHP

$conn = mysqli_connect($mysql_host, $mysql_user, $mysql_password,$mysql_database); 

if (mysqli_connect_errno()) { 
echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

$data    = file_get_contents("php://input"); 
$dataJsonDecode  = json_decode($data); 

$username = mysqli_real_escape_string($conn, $dataJsonDecode->username); 
$password = mysqli_real_escape_string($conn, $dataJsonDecode->password); 

echo $username.$password; 
$query = "SELECT * FROM user WHERE Username = '$username' and Password = '$password'"; 

$result = mysqli_query($conn,$query); 
$rowcount = mysqli_num_rows($result); 


/* if ($rowcount != 0) { 
    echo "Login Success"; 
    # code... 
}else{ 
    echo "Login Failed"; 
}*/ 

mysqli_close($conn); 

我使用这个PHP来找回我的登录功能,通过离子services.js

var baseUrl = 'http://mywebsite.com/'  
login: function (datalogin) { 
     return $http.post(baseUrl + 'ionic_do_login.php', datalogin, { 
      headers: { 
       'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8;' 
      } 
     }); 
    } 

该服务发送由我controller.js

.controller('LoginCtrl', function ($scope, $ionicPopup, Chats) { 
$scope.showAlert = function (msg) { 
    $ionicPopup.alert({ 
     title: msg.title, 
     template: msg.message, 
     okText: 'Ok', 
     okType: 'button-positive' 
    }); 
}; 

$scope.login = function (username, password) { 
    if (!username) { 
     $scope.showAlert({ 
      title: "Information", 
      message: "Username mohon diisi" 
     }); 
    } else if (!password) { 
     $scope.showAlert({ 
      title: "Information", 
      message: "Password mohon diisi" 
     }); 
    } else { 
     $scope.username = username; 
     $scope.password = password; 
     Chats.login({ 
      'username' : username, 
      'password' : password 
     }).then(function (res) { 
      $scope.showAlert({ 
       title: "Information", 
       message: res.data 
      }); 
     }); 

但每次我为我的应用程序,并尝试呼应trigerred,它不返回任何东西。

有帮助吗?

谢谢!

回答

0

有一些称为CORS的功能在浏览器中被禁用。它可能会阻止请求。尝试并在模拟器上运行应用程序。

如果您使用mozilla this扩展名将帮助您在浏览器上启用CORS。

+0

我通过更改我的服务和php上的内容类型找到了解决方案!谢谢! – Gwijaya

0

如果您使用新的Cordova库,则必须通过安装白名单插件启用http网络访问。你可以得到它here。默认情况下,cordova阻止交叉来源访问

+0

我通过更改我的服务和php的内容类型找到了解决方案!谢谢! – Gwijaya