构建$ http.get请求...错误

时间:2015-02-26 19:45:41

标签: javascript angularjs angularjs-directive request http-get

我正在使用AngularJS $ http.get尝试连接以下API。但是我无法构建正确的URL。

这是我想要使用的API网址

https://api.fda.gov/drug/event.json?search=receivedate:20040312

这是我的代码

return $http.get('https://api.fda.gov/drug/event.json?search=', {
  params: {
    receivedate: val
  }

但我的结果(错误)如下

GET https://api.fda.gov/drug/event.json?search=&receivedate=20040312 400 (Bad Request)

有人可以帮我正确构建吗?感谢

1 个答案:

答案 0 :(得分:2)

该参数为search而非receivedate

return $http.get('https://api.fda.gov/drug/event.json', {
  params: {
    search: 'receivedate:' + val
  }