Javascript 在收到ajax响应后使用const变量
我一直在做ReactJS。我在方法“fetch_data”中进行了一个ajax调用。一旦收到ajax响应,它将调用另一个方法“setLookupFValues” 现在,我想把变量“page”传递给“setLookupFValues”函数。我怎么做Javascript 在收到ajax响应后使用const变量,javascript,reactjs,ajax,Javascript,Reactjs,Ajax,我一直在做ReactJS。我在方法“fetch_data”中进行了一个ajax调用。一旦收到ajax响应,它将调用另一个方法“setLookupFValues” 现在,我想把变量“page”传递给“setLookupFValues”函数。我怎么做 export function fetchData(type, custom_name,keyword,page) { const controller = abortPreviousRequests('abortPreviousRequest
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)
})
}
使用
this.state.setLookupFValues(json,page)
而不是this.state.setLookupFValues(json)
,假设page
应作为setLookupFValues
函数的第二个参数。