function(){}中的局部变量和$.ajax()中succ
2017-07-27 本文已影响0人
Jacqueline_JS
<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>