2010-12-07 5 views
0

사용자 확인을 위해 j를 확인하십시오.알림 - jQuery 플러그인 확인

내 첫 번째 jConfirm은 사용자 작업을 위해 멈추지 않고 다음으로 넘어갑니다.

내 코드 :

$(function() { 

    $("#UpdateJobHandler").click(function() { 

     var JobHander = getJobHandler(); 
     if (JobHander.MaxInstances == 0) { 
       jConfirm('Continue?', 'Current Maximum Instances', function (ans) { 
        if (!ans) 
         return; 
       }); 
     } 

     var json = $.toJSON(JobHander); 

     $.ajax({ 
      url: '../Metadata/JobHandlerUpdate', 
      type: 'POST', 
      dataType: 'json', 
      data: json, 
      contentType: 'application/json; charset=utf-8', 
      success: function (data) { 

       var message = data.Message; 
       var alertM = data.MessageType; 
       if (alertM == 'Error') { 
        $("#resultMessage").html(message); 

       } 

       if (alertM == 'Success') { 
        $("#resultMessage").empty(); 
        alert(alertM + '-' + message); 
        action = "JobHandler"; 
        controller = "MetaData"; 
        loc = "../" + controller + "/" + action; 
        window.location = loc; 
       } 

       if (alertM == "Instances") { 
        jConfirm(message, 'Instances Confirmation?', function (answer) { 
         if (!answer) 
          return; 
         else { 
          var JobHandlerNew = getJobHandler(); 
          JobHandlerNew.FinalUpdate = "Yes"; 
          var json = $.toJSON(JobHandlerNew); 
          $.ajax({ 

           url: '../Metadata/JobHandlerUpdate', 
           type: 'POST', 
           dataType: 'json', 
           data: json, 
           contentType: 'application/json; charset=utf-8', 
           success: function (data) { 

            var message = data.Message; 
            $("#resultMessage").empty(); 
            alert(alertM + '-' + message); 
            action = "JobHandler"; 
            controller = "MetaData"; 
            loc = "../" + controller + "/" + action; 
            window.location = loc; 
           } 
          }); 
         } 
        }); 
       } 
      } 
     }); 
    }); 
}); 

내가 무엇을 놓치고? 이 모든 경우

답변

2

확실하지,하지만이 부분 :

if (JobHander.MaxInstances == 0) { 
      jConfirm('Continue?', 'Current Maximum Instances', function (ans) { 
       if (!ans) 
        return; 
      }); 
    } 

아마 당신이 원하는 것을하지 않습니다. function(ans) { ... } 함수가 종료되고 전체 처리기 (예 : $("#UpdateJobHandler").click(function() { ... })를 종료하려고합니다. 그렇다면 아래에서 수행 할 작업과 유사해야합니다. 즉, 반품 후 모든 것을 function(ans) { ... }에 넣어야합니다. 아마도 작은 함수로 분리하는 것이 가장 좋습니다.

편집 :이 라인을 따라 뭔가 :

function afterContinue() { 
     var json = $.toJSON(JobHander); 

     $.ajax({ 
      // ... all other lines here ... 
     }); 
    } 

    if (JobHander.MaxInstances == 0) { 
      jConfirm('Continue?', 'Current Maximum Instances', function (ans) { 
       if (ans) { 
        afterContinue(); 
       } 
      }); 
    } 

당신은 모든 success 기능과 유사한 일을 할 수 있습니다.

또 다른 예를 들어,이 같은 Instances 체크 다시 작성할 수 있습니다 :

  function afterInstances() { 
         var JobHandlerNew = getJobHandler(); 
         JobHandlerNew.FinalUpdate = "Yes"; 

         // ... and everything under else branch ... 
      } 

      if (alertM == "Instances") { 
       jConfirm(message, 'Instances Confirmation?', function (answer) { 
        if (answer) { 
         afterInstances(); 
        } 
       }); 
      } 

중요한을 - 몇 가지 이름을 가지고 (... afterContinue, afterInstances) 방법을 이름을 변경에서이 글을 읽는 사람에게 유용한 무언가를 의미 미래.

+0

감사합니다. icyrock, 더 작은 함수로 분할하여 이것을 다시 고려해 볼 수 있습니까? – Sreedhar

+0

@Nev_Rahd 편집을 참조하십시오. –

관련 문제