[英]How to update javascript variable after ajax call back
Ajax回調后如何更新javascript變量
var x =1;
$(document).on('click','.classname',function(){
console.log(x);
});
$.ajax({
type:'post',
url:tmplUri+'/ajax/test.php',
cache:false,
async:false,
data:{journey:'yes'},
success: function(data)
{
x = data;
}
});
在ajax調用之后,我需要更新該頁面上的變量
請給這個問題任何建議
為此,您需要一個globle變量,只需在ajax調用后調用另一個函數來重置變量
var x // make it globle
$(document).on('click','.classname',function(){
console.log(x);
});
function resetx(){
x =1;
}
$.ajax({
type:'post',
url:tmplUri+'/ajax/test.php',
cache:false,
async:false,
data:{journey:'yes'},
success: function(data)
{
x = data;
}
});
calling hierarchy
ajaxcall
resetx
than check you variable it will give you 1
這里的小提琴
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.