简体   繁体   中英

How to connect azure mobile services to ionic application

I have created a very simple ionic application with a login and username so far. I am currently using Microsoft azure mobile services to host my application. However I don't know how to work with a php file and a server. I am a beginner with working with servers thank you in advance.

PHP Code:

<?php
try {
    $conn = new PDO("microsoft azure connection string", "username", "password");
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
    print("Error connecting to SQL Server.");
    die(print_r($e));
}

?>

login controller :

 .controller('loginCtrl', ['$scope', '$stateParams', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
    // You can include any angular dependencies as parameters for this function
    // TIP: Access Route Parameters for your page via $stateParams.parameterName
    function ($scope, $stateParams) {

    $scope.User = {};
    $scope.login = function() {
    str="Dont know what to put here";
                $http.get(str)
                .success(function (response){  
          }).error(function() {                         //if login failed
                        var alertPopup = $ionicPopup.alert({
                            title: 'Login failed!',
                            template: 'Please check your credentials!'
                        });
                });
            };

    }])

login html

<ion-view title="Login" id="page6">
  <ion-content padding="true" class="has-header">
    <form id="login-form4" class="list">
      <ion-list id="login-list2">
        <label class="item item-input" id="login-input10">
          <span class="input-label">Username/Email</span>
          <input type="text" ng-model="User.email" placeholder="">
        </label>
        <label class="item item-input" id="login-input11">
          <span class="input-label">Password</span>
          <input type="password" ng-model="User.password" placeholder="">
        </label>
      </ion-list>
      <div class="spacer" style="height: 40px;"></div>
      <a id="login-button2" ng-click="login()" class="button button-positive  button-block">Log in</a>
      <a ui-sref="signup" id="login-button3" class="button button-positive  button-block button-clear">Or create an account</a>
    </form>
  </ion-content>
</ion-view>

Currently, the Azure App Service Mobile Apps SDK is provided for ASP.NET and Node.js web applications. So, you could switch your backend to Node.js or .NET backend instead.

Then you can create Easy API / Custom API in your mobile backend, and you are able to connect your API with invokeApi() of Javascript Clients for Azure Mobile Apps .

For more information, please refer to this blog post .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM