0

Passing parameter for $http with angular js.

$http({
                  method: 'get',
                  url: 'http://mmres.baganthandehotel.net/mmresadmin/invoicejson.php',
                  data: $.param({'chk': '2015-06-02'}),
                  headers: { 'Content-Type': 'application/json; charset=utf-8'}
                })
            .success(function(data){
                $scope.list = data;
                console.log($scope.list);
            }),

I can't received the value chk($_GET['chk']) from my server side.Why can't receive these parameter?

4 Answers 4

1

With HTTP GET request you can not post data to the server, Same things applies to angularjs $http get request.

But in angular js $http method we have option to pass query params, example is as below

$http({
    url: user.details_path, 
    method: "GET",
    params: {chk: '2015-06-02'}
 });

I think you should change your code like this ,

$http({
                  method: 'get',
                  url: 'http://mmres.baganthandehotel.net/mmresadmin/invoicejson.php',
                  params: {chk: '2015-06-02'},
                  headers: { 'Content-Type': 'application/json; charset=utf-8'}
                })
            .success(function(data){
                $scope.list = data;
                console.log($scope.list);
            }),

Sign up to request clarification or add additional context in comments.

Comments

0

Try:

$http.get('http://mmres.baganthandehotel.net/mmresadmin/invoicejson.php',{
                  params: {'chk': '2015-06-02'},
                  headers: { 'Content-Type': 'application/json; charset=utf-8'}
                })
            .success(function(data){
                $scope.list = data;
                console.log($scope.list);
            }),

Comments

0

Remove the quotation for 'chk' as shown :

              data: $.param({chk: '2015-06-02'}),

Comments

0

You will not get params value through $_GET you have to fetch params value by using file_get_contents because from angular you are making request with application/json content type.

$postData = json_decode(file_get_contents('php://input'), true);

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.