我有一段代码,在没加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("对不起,你输入的格式不对,无法进行保存");
}

解决方案 »

  1.   

    我找到原因了,我的代码是执行完之后直接关闭页面,但ajax执行好像需要一段时间,但那时页面已经关闭了,所以ajax没执行,但问题又来了,我要怎样才能让页面迟一点关闭呢,我是返回一个return true就关闭页面,用settime()这个函数写不来--!
      

  2.   

    这个是因为你这个$.post是异步取得数据,解决方法有两个:
    方法一、先设置   $.ajaxSetup({  
              async : false  
        });   
    然后再使用$.post方法二、直接用$.ajax $.ajax({   
          type: "post", 
           async : false, 
           url: "'Ajax.aspx'", 
           data: "",     
          success: function(result) {
             //成功以后的操作  
        });  
      

  3.   

    <script type="text/javascript">
        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>
      

  4.   

    我改用ajax就成功了,xiangyuhm真大神是也,其他几位大神对我帮助也很大,非常感谢了哈,java果然大神如云,小弟还得继续摸索