2009-10-06 5 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

+0

무엇을 의미합니까? 쉼표가없는 부분은 어디입니까? – acedanger

답변

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

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

+0

이것은 위대한 아이디어에 감사드립니다! – acedanger

관련 문제