dsfew215211 2012-01-27 10:47
浏览 31
已采纳

使用JQuery UI对话框返回false确认对话框

I am going to submit a form after validating the form as follows, here first I use a ajax post and check whether duplicate values are exist if exist ajax will return html code else return 'false'. Dialog box should popup if ajax return is a 'html code'. If ajax return is false form_validate() should return true. Which means no duplicates, form will submit for insert data. If user clicked Ok on the Dialog box, form_validate() should return true which means there are duplicates, form will submit for update data. If user clicked Cancel form_validate() should return false which means form will not submit. I am working on this hours but couldn't figure it out. Plz Help.

   function form_validate(){

         $.post('index.php',{ .....

                             },function(result){ 

                                if(result!='false'){
                                  $('<div></div>')
                                          .html(result+'<br/>Click OK to confirm.  Click Cancel to stop this action.')
                                          .dialog({
                                                         buttons : {
                                                                "OK": function() { 
                                                                   $(this).dialog("close");                       
                                                                   return true;
                                                                 }, "Cancel": function() {
                                                                        $(this).dialog("close");
                                                                         return false;
                                                                 }
                                 }
                                   }


             });



        }

<form> Tag

<form action="index.php" method="post" name="adminForm" onsubmit="return validate_form();" >        
  • 写回答

2条回答 默认 最新

  • dongrong8972 2012-01-27 12:06
    关注
    function form_validation(){
                 $.post
                  .....
                  .....
                ,function(result){        
    
    
    
                               if(result!='false'){
                                   $('<div></div>')   
                                          .html(result+'<br/>Click OK to confirm.  Click Cancel to stop this action.')   
                                          .dialog({   
                                       buttons : {
                                            "OK": function() { 
                                                  $(this).dialog("close");                       
                                                  $('#adminForm3').submit();
                                            }, "Cancel": function() {
                                                  $(this).dialog("close");
                                            }
                                       }});
                               }
                               else{                                  
                                   $('#adminForm3').submit();
                               }
                               return ;
    
                               });
    return false;
    }
    

    add form id as adminForm3. This will work fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备