【发布时间】: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,它就应该工作。请参阅这个使用
aspxstackoverflow.com/questions/2067472/… 的示例
标签: javascript jsonp