2017-12-30 32 views
0

jQuery를 DEFFERED. 그런 다음 경고 문을 실행 한 후 이 일을 어떻게 도와 드릴까요? 약속 (deferreds)을 기다리는는 jQuery를가 해결 여러 번

+0

[$ .when '()'(https://api.jquery.com/jquery.when/) _ "기반 콜백 함수를 실행하는 방법을 제공한다 on 0 개 이상의 객체, 일반적으로 비동기 이벤트를 나타내는 지연 객체입니다. "_ – Andreas

+0

@ Andreas는 답변을 제공해 주시면 귀하의 의견을 이해할 수 있습니다. –

답변

2

사용 $.when()

0 개 이상의 Thenable 개체, 비동기 이벤트를 나타냅니다 일반적으로 이연 개체를 기반으로 콜백 기능을 실행할 수있는 방법을 제공합니다 해결합니다.

$(document).on('click', '#Signup', function() { 
 
    console.log("Signup..."); 
 

 
    $.when(email_check('Signup'), mobile_check('Signup')) 
 
    .done(function(){ 
 
     console.log("All done!") 
 
    }); 
 
}); 
 

 
function email_check(Signup){ 
 
    var d = $.Deferred(); 
 
    
 
    setTimeout(function() { 
 
    \t console.log("email_check resolved"); 
 
    \t d.resolve(); 
 
    }, 1000); 
 
    
 
    return d; 
 
} 
 

 
function mobile_check(Signup){ 
 
    var d = $.Deferred(); 
 
    
 
    setTimeout(function() { 
 
    \t console.log("mobile_check resolved"); 
 
    \t d.resolve(); 
 
    }, 2000); 
 
    
 
    return d; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<button type="button" id="Signup">Signup</button>