javascript - 收到 ajax 响应后使用 const 变量
问题描述
我一直在研究 ReactJS。我在方法“fetch_data”中进行了 ajax 调用。一旦收到 ajax 响应,它就会调用另一个方法“setLookupFValues”。
现在,我想将变量“page”传递给“setLookupFValues”函数。我该怎么做?
export function fetchData(type, custom_name,keyword,page) {
const controller = abortPreviousRequests('abortPreviousRequests')
abortableFetch(`${ROOT_URL}/fetch_data.json?type=${type}&custom_name=${custom_name}&key_word=${keyword}&page=${page}`, {
signal: controller.signal
})
.then((response) => {
return response.json()
}).then((json) => {
this.state.setLookupFValues(json)
}).catch((ex) => {
if (ex.name === 'AbortError') {
console.log('request aborted')
}
console.log('parsing failed', ex)
})
}
解决方案
推荐阅读
- visual-studio - 有没有办法单独运行代码分析功能?视觉工作室
- android - 为什么我的 android studio 3.5.3 中缺少“app”文件夹
- r - 阅读带有模式的最新 csv
- python - 生成位置列表 (1, (2, 3), 4, (5, 6)) 如何?
- security - 在 Micronaut 中 OAuth 登录后如何重定向回原始 URL
- asp.net-core - 我按照文档中的建议配置了 IIS ApplicationInitialization addinitializationPage='/warm-up'
- angular - 如何创建 Angular 的路由 pathMatch 无限循环?
- xpages - XPages:如何在 SSJS 中使用“搜索”属性获取 dominoView 数据源的文档集合
- javascript - 是否可以通过反应(钩子)在另一个上下文中使用上下文?
- mysql - 在终端中运行 mysql 命令时如何在 mac OS 中指定默认用户?