如何将变量userID移出其范围(一旦从ajax POST调用返回),因为我需要它的'value(在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}
})
答案 0 :(得分:3)
移动进入ajax成功?
$.ajax({
url: '/auth',
type: 'POST',
data: {
token: idToken
},
success: function (response) {
var userID = response.userID
$.get({
url: '/members-area/',
data: {
userID: userID
}
})
}
})