[英]How to update javascript variable after ajax call back
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;
}
});
after ajax call i need to update the variable on that page 在ajax调用之后,我需要更新该页面上的变量
Please give any suggestion for this issue 请给这个问题任何建议
for this you need a globle variable, just Call a another function to reset you variable after ajax call 为此,您需要一个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.