当php的头为json的时候
js代码:
var a = 1;
$ajax post 那个php接口以后
回调函数设置 a = 2;
但是a 还是 1;
有人知道为什么吗?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test jq ajax</title>
<script src="jquery.js"></script>
</head>
<body>
<a href="###" id="abc">123</a>
<a href="###" id="bbb">2</a>
<script type="text/javascript">
$(document).ready(function(){
var a;
$("#bbb").bind('click',function(){
$.ajax({
url:'1.php',
type:'post',
data:{},
success:function(){
a = {a:1};
console.log(a);
alert(1)
}
})
});
$('#abc').bind('click',function(){
console.log(a);
})
});
</script>
</body>
</html>
js代码:
var a = 1;
$ajax post 那个php接口以后
回调函数设置 a = 2;
但是a 还是 1;
有人知道为什么吗?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test jq ajax</title>
<script src="jquery.js"></script>
</head>
<body>
<a href="###" id="abc">123</a>
<a href="###" id="bbb">2</a>
<script type="text/javascript">
$(document).ready(function(){
var a;
$("#bbb").bind('click',function(){
$.ajax({
url:'1.php',
type:'post',
data:{},
success:function(){
a = {a:1};
console.log(a);
alert(1)
}
})
});
$('#abc').bind('click',function(){
console.log(a);
})
});
</script>
</body>
</html>