【问题标题】:JSONP: Uncaught ReferenceErrorJSONP:未捕获的引用错误
【发布时间】:2017-06-17 07:56:43
【问题描述】:

我有这个代码。我在我的 React-Redux 应用程序中使用 fetch-jsonp 库。

export function fetchAirBnbData() {
  return function (dispatch) {
    fetchJsonp('http://assets.airbnb.com/frontend/search_results.js', {
     jsonpCallback: 'search_results',
   })
      .then(function (response) {
        console.log(response)
        return response.json()
      }).then(function (json) {
       console.log('parsed json', json)
       dispatch(loadAirBnBData(json))
      }).catch(function (ex) {
       console.log('parsing failed', ex)
     })
 }
}

我收到了这个错误

Uncaught ReferenceError: search_results is not defined

据我所知,这应该可行。有什么想法吗?

【问题讨论】:

  • 在search_results之后是否需要()
  • @ModarNa 否,因为这是回调函数的字符串,而不是函数本身。
  • 从文档中我看到他们正在调用 .jsonp 文件,这可能是问题
  • 扩展名无关紧要。只要输出是 JSONP,它就应该工作。请参阅这个使用 aspx stackoverflow.com/questions/2067472/… 的示例

标签: javascript jsonp


【解决方案1】:

我是fetch-jsonp的作者,你应该使用

fetchJsonp('http://assets.airbnb.com/frontend/search_results.js', {
  jsonpCallbackFunction: 'search_results',
})

【讨论】:

    猜你喜欢
    • 2018-05-04
    • 2013-04-05
    • 2014-05-27
    • 1970-01-01
    • 2013-10-27
    • 2014-10-11
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多