gpt4 book ai didi

javascript - 如何将变量移出作用域?

转载 作者:行者123 更新时间:2023-11-28 17:59:29 29 4
gpt4 key购买 nike

如何将变量 userID 移出其范围(一旦从 ajax POST 调用返回),因为我需要下面的值(在 GET 请求中)?我应该使用回调吗?

firebaseAUTH.signInWithEmailAndPassword(email, password).then(function (user) {
console.log('user has signed in with e-mail address: '+user.email+' and user ID: '+user.uid)
firebaseAUTH.currentUser.getToken(true).then(function(idToken) {
// Send token to your backend via HTTPS (JWT)
$.ajax(
{
url: '/auth',
type: 'POST',
data: {token: idToken},
success: function (response){
var userID = response.userID
//set database ref, pull out info based on ID
}})
$.get(
{
url: '/members-area/',
data: {userID: userID}
})

最佳答案

移动到ajax里面获取成功吗?

$.ajax({
url: '/auth',
type: 'POST',
data: {
token: idToken
},
success: function (response) {
var userID = response.userID

$.get({
url: '/members-area/',
data: {
userID: userID
}
})
}
})

关于javascript - 如何将变量移出作用域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43832976/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com