2013-03-21 103 views
0

我对jQuery和Javascript相当新。我的问题是与jQuery UI对话框。我有桌子在哪里点击一行,并在对话框中填充更多细节。对话框里会有一个表格和一个表格。当用户输入详细信息并在表单上单击时,我会检查用户输入并再次将该表单显示回对话框中,但是当发生这种情况时,对话框关闭按钮不起作用。对话框关闭不起作用的对话框中的Ajax调用

有人可以建议如何处理这个请吗?感谢您的帮助。

$.ajax({ 
    type:"POST", 
    dataType:"html", 
    url:"form/add/"+estimateId, 
    cache:false, 
    //data:a, 
    success:function(html){ 
     //alert(html); 
     $(".projectMaintenance").html(html); 
     $(".projectMaintenance").dialog({ 
      resizable:false, 
      height:750, 
      width:900, 
      modal:true, 
      buttons:{ 
       "Close":function(){ 
        $(this).dialog('destroy'); 
    .... 

这是我用来在对话框中提交表单的脚本。

var a=$('form').serialize(); 

$.ajax({ 
    type:"POST", 
    dataType:"html", 
    url:"form/save", 
    cache:false, 
    data:a, 
    success:function(html){ 
     alert(html); 
     $(".projectMaintenance").html(html); 
....... 

回答

1

你只是在执行用户Ajax请求中选择关闭选项,保持一点更具可读性和友好,创建一个trySend()函数

$.ajax({ 
     type:"POST", 
     dataType:"html", 
     url:"form/add/"+estimateId, 
     cache:false, 
     //data:a, 
     success:function(html){ 
      //handle if everything it's ok and should show the dialog.... 
      $(".projectMaintenance").html(html); 
      $(".projectMaintenance").dialog({ 
       resizable:false, 
       height:750, 
       width:900, 
       modal:true, 
       buttons:{ 

        "Close":function(){ 


         $(this).dialog('destroy'); 


         buttons: { 
          "Close": function() { 
           $(this).dialog('close'); 
           trySend(); 
          } 
         } 

........ .....

而且trySend功能

 function trySend(){ 
      var a=$('form').serialize(); 
      $.ajax({ 
       type:"POST", 
       dataType:"html", 
       url:"form/save", 
       cache:false, 
       data:a, 
       success:function(html){ 
        alert(html); 

        $(".projectMaintenance").html(html); 
       }); 
     } 
+0

谢谢你,对不起延迟。我遵循你的建议,现在工作正常。 – VBJ 2013-03-22 16:10:10