2

I have created a jsfiddle, were i am tring to perform a http get using $http when clicked on the test button, The syntax and the structure of $http.get seems correct to me, but it is not sending the selected params (query string {data:$scope.newuser}) in the url.

here is the fiddle :

jsfiddle.net/8sZLs/2/

And at php side i tried , But not showing the values posted

3 Answers 3

7

You cannot send an object with get, you need to make a post request as following.

 $http({ url: 'request-url', method: "POST", data: { 'message' : message } }) 

As @YauheniLeichanok suggested, another way is to use query parameters, params of $http.get, in this case the strings you pass will appear as: ?key1=value1&key2=value2

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

3 Comments

Just as an option - you can also use 'params' instead of 'data' to append your data to the query string. It will work for GET.
@anvarik, can you tell me how to get this in the php side <?php print_r($_POST['message']); ?>, not showing the values
@RaviMone, I am not familiar with PHP, but just use the following angular code: $http.post('http://' + host + ':' + port + '/echo/html', $scope.newuser) it should post your user
3

Replace your $http.get line with this

$http.get('/echo/html/', {params:$scope.newuser}); 

Comments

1

On how to get the values at the server side PHP.

Have to use php standard input

$data = file_get_contents("php://input"); $objData = json_decode($data); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.