Error consuming web service with POST and GET in Angularjs


Hi, I have a problem that keeps me from moving forward. I have a Web Service in which it asks to enter coordinates (INPUT); these, if they are correct, will send in JSON format a list of the name of the nearby branches (OUTPUT).

You can see it here:


The issue is that I could not manage to send the parameters to get this information ( lat , long ) from FrontEnd.


  • Input:

    lat ( float ): GPS latitude

    long ( float ): GPS length

  • Output:

    List of companies and branches with the following parameters: id_sucursal , direccion , nombre_empresa , distancia .

    Access: link

Code: I understand this, I know it is wrong and I would like if you can help me to correct and complete it, please, and I have seen too many videos, I have been able to achieve connection with a get, without sending parameters, as in the courses, but this nothing.

function comotellames($scope, $http) {
        url: '',
        method: "POST",
            latitud=  ???
            longitud= ??
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    .success(function (data, status, headers, config) {


        id_sucursal, direccion, nombre_empresa, distancia. ??

    }).error(function (data, status, headers, config) {
        $scope.status = status; 
asked by Hernan Humaña 01.09.2016 в 05:40

2 answers


Seeing the page that references it seems to me that the error is in how you use the promises. You are using success and error which are obsolete methods. Instead type then and catch , you also have some syntax errors.

You have to use ng-model in the input and then use the $scope with its corresponding binding to get the value

<input class="form-control" ng-model="lat">

is obtained using


It should look like this

angular.module('app', [])
  .controller('CoordenadasCtrl', function($scope, $http) {
    $scope.enviar = function() {
          url: '',
          method: "POST",
          data: {
            lat: $,
            lng: $scope.lng
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        .then(function(response) {
        }).catch(function(error) {
<link href="" rel="stylesheet" />
<script src=""></script>
<div ng-app="app" ng-controller="CoordenadasCtrl" class="form-horizontal">
  <div class="form-group">
    <label class="col-md-3 control-label">Latitud</label>
    <div class="col-md-9">
      <input class="form-control" ng-model="lat">
  <div class="form-group">
    <label class="col-md-3 control-label">Longitud</label>
    <div class="col-md-9">
      <input class="form-control" ng-model="lng">

  <button type="button" ng-click="enviar()" class="btn btn-primary">Enviar</button>

Note: The snippet does not work because it gives access denied. The code should work well on your server since it does not do CORS.

answered by 01.09.2016 в 14:28

The data field must be an object. It does not have the correct syntax, it should be something like:


And it should work, besides the line that is after the console does not seem to make sense.


answered by 01.09.2016 в 14:23