var myArray = {};
var cpuNumMax = 1;
var cpuNumMin = 1;
function getVMProductByTypeMap(){
$.ajax({
url:"<%= request.getContextPath()%>/service/selfservice/getProductByTypeMap",
type:"post",
dataType:"json",
data:{"typeId":"1"},
cache: false,
asycn:false,
success: function (data) {
if(data != null && data != ""){
alert(data[0].cpuNumMax);////查到的值是32
cpuNumMax = parseInt(data[0].cpuNumMax);
cpuNumMin = parseInt(data[0].cpuNumMin);
for(var i=0; i<data.length; i++){
var memMax = data[i].memMax;
var memMin = data[i].memMin;
var cpuNum = data[i].cpuNum;
myArray[cpuNum] = memMin+"|"+memMax;
}
}
return resultFlag;
//console.log(myArray);
},
error:function(){
alert("error");
}
});
}
$(document).ready(function(){
getVMProductByTypeMap();
console.log(cpuNumMax); //1
});
ajax中我已使用了同步,但 为什么console.log(cpuNumMax); 输出是1,就是ajax中没有为其赋值 ?