我有一段代码,在没加alert()时,功能无法实现,在加了alert()之后,代码能成功运行,对于一个新手的我来说,这简直就是世界十大未解之谜啊,求大神赐教
type = "in";
nextCell = dhxGrid.cells(selId,3).getValue();
if(ishhmm(cellValue)){
if(cellValue>nextCell){
alert("时间顺序不对,没法保存");
}else{
$.post("${ctx}/DetAttendance.do?action=upDateAtt",
{Rid: selId, value: cellValue,type:type,dhtmYear:dhtmYear}
);
alert("您修改的内容已保存"); //就是这个alert,不加ajax功能就无法实现
}
}else{
alert("对不起,你输入的格式不对,无法进行保存");
}
type = "in";
nextCell = dhxGrid.cells(selId,3).getValue();
if(ishhmm(cellValue)){
if(cellValue>nextCell){
alert("时间顺序不对,没法保存");
}else{
$.post("${ctx}/DetAttendance.do?action=upDateAtt",
{Rid: selId, value: cellValue,type:type,dhtmYear:dhtmYear}
);
alert("您修改的内容已保存"); //就是这个alert,不加ajax功能就无法实现
}
}else{
alert("对不起,你输入的格式不对,无法进行保存");
}
方法一、先设置 $.ajaxSetup({
async : false
});
然后再使用$.post方法二、直接用$.ajax $.ajax({
type: "post",
async : false,
url: "'Ajax.aspx'",
data: "",
success: function(result) {
//成功以后的操作
});
type = "in";
nextCell = dhxGrid.cells(selId,3).getValue();
if(ishhmm(cellValue)){
if(cellValue>nextCell){
alert("时间顺序不对,没法保存");
}else{
$.post("${ctx}/DetAttendance.do?action=upDateAtt",{Rid: selId, value: cellValue,type:type,dhtmYear:dhtmYear},function(data){
alert(data);//data是/DetAttendance.do?action=upDateAtt页面返回的结果,由你定义保存成功还是失败,但你不能马上关了页面,给点时间。
//如果你有关闭动作就写这里!
});
}
}else{
alert("对不起,你输入的格式不对,无法进行保存");
}
</script>