为什么我的Angular前端不传递正确的$http ?获取参数到Django后端
Why won't my Angular front-end pass correct $http.get parameters to Django back-end?
我有一个Web应用程序,由前端客户端用Angular/Javascript编写,后端服务器用Python/Django编写。
我试图做一个简单的http GET请求从客户端到服务器,它不工作。失败的原因是由于某些未知的原因,没有正确传递参数。
下面是我的客户端调用的代码行:
$http.get(API + '/api/getProfile', {'profileId':5}).then(console.log('A'), console.log('B'));
下面是我的服务器上的相关代码行:
class GetProfileAPI(views.APIView):
def get(self, request, *args, **kwargs):
logger.info("request.get_full_path() = %s" % request.get_full_path())
profile_id_arg = request.GET.get('profileId')
logger.info("profile_id_arg = %s (%s)" % (profile_id_arg, type(profile_id_arg)))
# Do something here if profile_id_arg is not None.
当我运行这段代码时,我希望服务器端的profile_id_arg
是字符串5
。但是看看我得到的输出:
request.get_full_path() = /api/getProfile
profile_id_arg = None (<type 'NoneType'>)
为什么不能正确接收profile_id
,我该如何解决这个问题?代码示例会有所帮助。
HTTP GET请求不能包含要发送到服务器的数据。但是,您可以在请求中添加查询字符串。
$http.get(API + '/api/getProfile', {params:{'profileId':5}})
.then(function (response) { /* */ })...
或
$http({
url: API + '/api/getProfile',
method: "GET",
params: {'profileId':5}
});
check here1 and check here2
相关文章:
- Typescript angularjs$http获取响应类型(避免使用<any>)
- 从http获取响应管理zip
- 从angular$http获取promise数据
- nodejs-如何安全地将令牌从http获取请求传递到html页面
- $http.获取和$http.JSONP未能获得Google API响应
- 如何在ionic中使用$http获取特定的用户内容
- Angularjs无法通过http获取请求
- 修复在执行http获取请求angularJS时的竞争条件
- ionic http获取到本地文件会给出http错误代码0
- HTTP 获取节点 JS 以使用文档元素进行解析
- $http.获取同步 AngularJS
- AngularJS$http.获取当时和成功回调之间的区别
- 节点.js:HTTP 获取请求
- AngularJS :从$http获取缓存结果
- AngularsJS$http获取数据,但没有显示
- Angularjs - 使用 $http 获取 xml 响应而不是 json
- 使用 Http 获取 角度服务
- AngularJS链接$http获取请求
- $http获取逻辑以仅允许 200 OK
- 如何下载由 php readfile() 发送的文件,由 AngularJs 触发$http获取