首页 > 代码库 > js 变量获取ajax返回值,要改为同步

js 变量获取ajax返回值,要改为同步

   var html=resource(1);

function resource(page){
var html="";
var dr=‘<%=imageSer%>‘;
$.ajax({
type:"post",
data:{page:page,rows:"5"},
async: false,
dataType:"json",
url:"",
success:function(data){
$.each(data.rows,function(i,n){
var src =http://www.mamicode.com/dr+n.image_url;
html +=‘<div class="cell"><a href="http://www.mamicode.com/#"><img src="http://www.mamicode.com/‘+src+‘" /></a><p>‘+n.title+‘</p></div>‘;
});
console.log(html);
}
});
return html;
}

js 变量获取ajax返回值,要改为同步