Angularjs $http get method not sending any params

谁都会走 提交于 2019-12-24 06:16:28

问题


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


回答1:


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




回答2:


Replace your $http.get line with this

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



回答3:


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);


来源:https://stackoverflow.com/questions/22660012/angularjs-http-get-method-not-sending-any-params

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!