<button>btn</button>
<script>
$("button").click(function () {
var myname="jac";
$.ajax({
type:"GET",
url:"x.php",
success:function (data) {
alert(myname);
},
error:function () {
alert("发生错误");
}
});
});
//在function(){}中success外定义的变量在success中能访问到
</script>
<button>btn</button>
<script>
$("button").click(function () {
$.ajax({
type:"GET",
url:"x.php",
success:function (data) {
var myname="jac";
},
error:function () {
alert("发生错误");
}
});
alert(myname);
});
//在success里定义的变量在function(){}中访问不到
</script>
网友评论