AngularJS将数据传递到$ http.get要求 [英] AngularJS passing data to $http.get request
问题描述
我有一个函数,做了HTTP POST请求。在code如下规定。这工作得很好。
I have a function which does a http POST request. The code is specified below. This works fine.
$http({
url: user.update_path,
method: "POST",
data: {user_id: user.id, draft: true}
});
我对HTTP GET另外一个功能,我想将数据发送到该请求。但我没有在得到那个选项。
I have another function for http GET and i want to send data to that request. But i dont have that option in get.
$http({
url: user.details_path,
method: "GET",
data: {user_id: user.id}
});
有关http.get的语法是
The syntax for http.get is
获取(URL,配置)
有人可以帮助我。
推荐答案
一个HTTP GET请求不能包含数据被发送到服务器。但是,您可以查询字符串添加到请求。
A HTTP GET request can't contain data to be posted to the server. However you can add a query string to the request.
angular.http为此提供了一个选项, PARAMS
。
angular.http provides an option for it params
.
$http({
url: user.details_path,
method: "GET",
params: {user_id: user.id}
});
请参阅: http://docs.angularjs.org/api/ng.$http#get一>和<一个href=\"https://docs.angularjs.org/api/ng/service/$http#usage\">https://docs.angularjs.org/api/ng/service/$http#usage (显示 PARAMS
参数)
See: http://docs.angularjs.org/api/ng.$http#get and https://docs.angularjs.org/api/ng/service/$http#usage (shows the params
param)
这篇关于AngularJS将数据传递到$ http.get要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!