2009-10-06 43 views
0

当我单击“导出”URL时,发生以下两个事件。无论我如何尝试,我都无法将这两者结合在一起,因为没有收到“嘿,你在某处丢失了逗号或分号” - 错误。任何人都可以提出将两者结合的方法,还是应该让他们像现在一样分开?如何在单击URL时执行两个函数

$('#export').click(function() { 
     $.each(gSelectedMeds, 
      function(intIndex, objValue) { 
       i=intIndex + 1; 
       if(i>1) {string+='&';} 
       string+='med'+i+'="'+objValue+'"'; 
      } 
     ) 
      string += "&count="+i; 
    }); 
    $('#export').click(function(){ 
     $.ajax({ 
      url: 'ajax-exportMeds.php?'+string, 
      type: "GET", 
      dataType: "text", 
      success: 
       function(data){ 
        $('#dialog_layer').dialog({ 
         autoOpen: true,       
         bgiframe: true, 
         modal: true, 
         buttons: { 
          "OK": 
           function() { 
            $(this).dialog("close"); 
           } 
         } 
        }) 
       } 
     }) 
    }); 
+0

它看起来像你有更多的问题比一个缺失的逗号 – scottm 2009-10-06 02:50:19

+0

你是什么意思?我错在哪里逗号? – acedanger 2009-10-06 02:52:34

回答

1

我不知道这是否会做到这一点,但组合成一个函数可以消除可能导致您问题的全局“字符串”。

$('#export').click(function() { 
    $.each(gSelectedMeds, 
    function(intIndex, objValue) { 
     i=intIndex + 1; 
     if(i>1) {string+='&';} 
     string+='med'+i+'="'+objValue+'"'; 
    } 
    ) 

    string += "&count="+i; 

    $.ajax({ 
      url: 'ajax-exportMeds.php?'+string, 
      type: "GET", 
      dataType: "text", 
      success: function(data){ 
       $('#dialog_layer').dialog({ 
       autoOpen: true,             
       bgiframe: true, 
       modal: true, 
       buttons: { 
        "OK": function() { $(this).dialog("close"); } 
        }  
       }) 
      } 
    }) 
}); 
+0

好主意。我更喜欢这个。非常感谢你!! – acedanger 2009-10-06 03:04:28

0

你试过这个吗?

function doEach() { 
     $.each(gSelectedMeds, 
       function(intIndex, objValue) { 
         i=intIndex + 1; 
         if(i>1) {string+='&';} 
         string+='med'+i+'="'+objValue+'"'; 
       } 
     ) 
       string += "&count="+i; 
} 

function doAjax(){ 
     $.ajax({ 
       url: 'ajax-exportMeds.php?'+string, 
       type: "GET", 
       dataType: "text", 
       success: 
         function(data){ 
           $('#dialog_layer').dialog({ 
             autoOpen: true,             
             bgiframe: true, 
             modal: true, 
             buttons: { 
               "OK": 
                 function() { 
                   $(this).dialog("close"); 
                 } 
             } 
           }) 
         } 
     }) 
    } 

$('#export').click(function() { 
    doEach(); 
    doAjax(); 
}); 

你也应该把有意义的名字。当然,你可以重构这些代码更容易。

+0

不,我没有试过 – acedanger 2009-10-06 02:53:22

+0

这个工作很好,谢谢你的想法! – acedanger 2009-10-06 03:02:06

相关问题