$.ajax()默认是同步请求,如果同时发出几个请求,会出现请求与返回数据不同步现象。其原因是没有设置异步;使用属性async: false,来设置为异步请求
$.ajax({
url: "<%=context%>/dms-select/chnlSetCardAction!loadProductType.do",type:"post",
async: false,
data:'',
success: function(data) {
var datas = $.evalJSON(data);
if(datas.success){
var html = "<option value=''>全部</option>";
var list = datas.obj.msgbody.list;
if(list.length > 0){
for(var i=0; i<list.length; i++){
html += "<option value='"+list[i].product_id+"'>"+list[i].product_name+"</option>";
}
$("#productType").append(html);
//注册onchange事件
$("#productType").change(function(){
createTable($(this).val(),'','');
//alert($(this).val());
});
}
}
},
error: function(data) {
$.messager.alert('提示信息','系统调用类别接口操作出现异常!','error');
}
});