今天学习了showloading函数,在写一个画图函数的时候遇到了一个奇怪的问题,我将ajax设为异步的时候也就是下面的这段代码能够正确执行,当我设置为false也就是同步的时候下面这段代码却出现showloading函数未展现出loading的效果,直接进行等待画图。看了关于同步和异步的一些解释还是没有解答心中的疑惑,待日后解决!
function create(){
var chart;
var mydata=[];
$("body").hideLoading();
$.ajax({
url: 'data/graghjson.php',
dataType:"json",
data:{year: $("#year").combobox('getValue'),
yue: $("#month").combobox('getValue'),
fbnum: $("#fubiaohao").combobox('getValue'),
canshu: $("#canshu").combobox('getValue'),},
type:'POST',
async:true,
beforeSend:function(){
alert("数据执行前");
$("body").showLoading();
},
success:function(point){
$("body").hideLoading();
var obj=eval(point);
for (var i=0; i<obj.length; i++){
mydata.push([
Date.parse(obj[i].time),
parseFloat(obj[i].temp)
]);
};
ytimu=point[0].name;
biaoti=ytimu+'观测曲线图';
chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
title: {
text: biaoti,
x: -20 //center
},
xAxis: {
title: {
text: '时间'
},
labels: {
formatter: function() {
return Highcharts.dateFormat('%Y/%m/%d', this.value);
}
}
},
yAxis: {
title: {
text: ytimu
}
},
credits: {
text: '',
href: ''
},
series: [{
name: ytimu,
data : mydata
}]
});
$('#w').window('open');
},
error: function(){alert('error!')},
});
}