调用ajax的返回值,需要再ajax之外的函数体里return,以及同步异步问题

<html>
<head>
<meta charset="utf-8"/>
<script src="js/jquery-1.10.2/jquery-1.10.2/jquery.js"></script>
<script type="text/javascript">
</script>
</head>
<body>
<script type="text/javascript">
 
function demo1(){
var result=1;
$.ajax({
url : '',
type : "get",
data : {},
async : true,
success : function(data) {
result = 2;
 
}
});
return result; //2
}

alert(demo1());
</script>

</body>
</html>
posted on 2019-04-30 17:50  2015熊出没  阅读(180)  评论(0编辑  收藏  举报