1

In my Rest.in.php

private function set_headers(){
        header("HTTP/1.1 ".$this->_code." ".$this->get_status_message());
        header("Content-Type:".$this->_content_type);
    }

I used jquery and got response

    <script>
    $(document).ready(function(){
        $("button").click(function(){
            alert("haha");
            $.post("http://localhost/fudline/access/hotels/loadplaces",
            {
              district: "Malappuram"
            },
            function(data,status){
                alert(data);
                console.log(data);
                console.log(status);
            });
        });
    });
    </script>

How to call angular http post for this...I tried below code and not going to success() function..I need to use angular js because I want use ng-repeat.

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
    $scope.loadPlace = function(x) {
      alert(x);
      $http({
        method: 'POST',
        url: 'http://localhost/fudline/access/hotels/loadplaces',
        data: { district: "Malappuram"},
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
        })
      .success(function(data, status, headers, config) {
          alert("haha");
          alert(data);
          $scope.places = data;
      }).error(function(data, status, headers, config) {
          //
      });



    }
</script>
0

1 Answer 1

1

You need to serialize the data yourself as the $http default is to serialize as json not urlencoded which is the default for $.ajax

Inject $httpParamSerializerJQLike service and change:

data: { district: "Malappuram"},

To

data: $httpParamSerializerJQLike({ district: "Malappuram"}),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.