我需要使用 AngularJS 的 $http 调用 Parse RESTFUL API 检索特定数据,Parse 允许我执行此操作的唯一方法是将“--data-urlencode where={"storeId":2}"发送到 curl 调用。
curl -X GET -H "X-Parse-Application-Id:ApplicationId" -H "X-Parse-REST-API-Key: ApiKey" -G --data-urlencode 'where={"storeId":2}' <a href="https://api.parse.com/1/classes/Stores/" rel="noreferrer noopener nofollow">https://api.parse.com/1/classes/Stores/</a>
请参阅此处:https://parse.com/docs/rest#queries-arrays
我可以使用终端返回 JSON 结果,但不能使用 $http()。任何人都知道我如何将“--data-urlencode where = {”storeId“:2}”注入(inject)到AngularJS $ http()或$resource()方法中?
请参阅此处:http://docs.angularjs.org/api/ng.$http
最佳答案
查看解析 api 的 python 引用,我猜想 where={"storeId":2}
可以作为查询参数附加(如果不访问解析 api,我无法测试它)。来自引用:
params = urllib.urlencode({"where":json.dumps({
"arrayKey": 2
})})
在 AngularJS 中,您可以使用 $http
的 config
对象中的 param
键添加查询参数:
var req = $http({
params: {
where: {storeId: 2},
},
headers: {
'X-Parse-Application-Id': 'ApplicationID',
'X-Parse-REST-API-Key': 'ApiKey'
}
//... other params, like URL
});
params.where
值将自动转换为 JSON 字符串。我不确定查询参数是否默认进行 URL 编码,如果没有,请手动对它们进行 JSON 编码并应用 encodeURIComponent
函数。
关于javascript - AngularJS/解析 $http --data-urlencode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17199066/