按钮不能工作

时间:2016-10-27 08:31:12

标签: javascript php angularjs ionic-framework

我想使用ionic和angularjs登录。当我完成我的代码并运行到我的浏览器时,该按钮无法正常工作。有人可以帮帮我吗?我是离子

的新人

我的登录视图:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link rel="manifest" href="manifest.json">

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
   <script src="js/app.js"></script>
  </head>
  <body ng-app="apps" ng-controller="PostController as postCtrl">
   <ion-view view-title="Please Sign in">
  <ion-content class="padding">
    <div class="list">
      <label class="item item-input">
        <input type="text" placeholder="Name" ng-model="postCtrl.inputData.username">
      </label>
      <label class="item item-input">
        <input type="password" placeholder="Password" ng-model="postCtrl.inputData.password">
      </label>
    </div>
    <div class="alert alert-danger" role="alert" ng-show="errorMsg">{{errorMsg}}</div>
    <button class="button button-full button-balanced" ng-click="postForm">Sign In</button>
  </ion-content>
</ion-view>
  </body>
</html>

模块&amp;控制器:     angular.module(&#39; starter&#39;,[&#39; ionic&#39;])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {

      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

.controller('PostController', ['$scope', '$http', function($scope, $http) {

    $scope.postForm = function() {

      var encodedString = 'username=' +
        encodeURIComponent($scope.inputData.username) +
        '&password=' +
        encodeURIComponent($scope.inputData.password);

      $http({
        method: 'POST',
        url: 'check-login.php',
        data: encodedString,
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
      })
      .success(function(data, status, headers, config) {
        console.log(data);
        if ( data.trim() === 'correct') {
          window.location.href = 'home.html';
        } else {
          $scope.errorMsg = "Login not correct";
        }
      })
      .error(function(data, status, headers, config) {
        $scope.errorMsg = 'Unable to submit form';
      })
    }

  }]);

php文件:

<?php 
if ( $_POST['username'] === 'Test' && 
    $_POST['password'] === '1234' ) {
        echo 'correct';
} else {
        echo 'wrong'; 
}

?>

2 个答案:

答案 0 :(得分:2)

尝试在ng-click之后使用函数make(),如下所示:

<button class="button button-full button-balanced" ng-click="postForm()">Sign In</button>

让我知道。

答案 1 :(得分:2)

ng-click = postForm

错误

试试这个

 `<button class="button button-full button-balanced" ng-click="postForm()">Sign In</button>`