No response from server when trying to POST via Appgyver/Angular js

569 views Asked by At

I'm relatively new to using Appgyver and I'm having a bit of an issue when trying to connect to a remote server using POST. I'm not sure if the issue is from the server side as the alerts set up on success/failure of posting are not appearing. Here are snippets of my code.

Index.html

<div ng-controller="IndexController">

  <super-navbar>
    <super-navbar-title>
      Index
    </super-navbar-title>
  </super-navbar>

  <div class="padding">
  <input type="text" ng-model="username" placeholder="Username">
  <input type="text" ng-model="password" placeholder="Password">
    <button class="button button-block button-positive" ng-click="getPosition()">Log in</button>
</ul>

    </div>

</div>

IndexController.js

angular
  .module('geolocation')
  .controller('IndexController', function($scope, supersonic) {
      $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
    // Controller functionality here
      $scope.getPosition = function() {


        var data = 
        {
            'email': $scope.username,
            'password': $scope.password
        }

        $http.post('http://www.example.co.za/mobile.php', data)
        .success(function(data, status, headers, config) {
            supersonic.ui.dialog.alert('Success');
        })
        .error(function(data, status, headers, config) {
            // show error details
            supersonic.ui.dialog.alert('Epic fail');
        });
    };
  });

The headers used in the php file on my server are:

header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Headers: X-PINGOTHER');
header("Access-Control-Max-Age: 2520");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE, XMODIFY");
1

There are 1 answers

0
Glycho On

Working now, turns out the function parameters needed to include $http. After updating the code all works correctly. The updated code should read:

.controller('IndexController', function($scope, supersonic, $http) {