首页 > 代码库 > jquery promise (Deferred)

jquery promise (Deferred)

 

<!DOCTYPE html><html><head>  <meta charset="UTF-8">  <title>jquery promise</title></head><body>  <div id="app">    <div id="result"></div>  </div>  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  <script>    $(‘#result‘).html(‘waiting data...‘);      var promise = wait();      promise.done(result);      function result() {        $(‘#result‘).html(‘done‘);      }      function wait() {        var deferred = $.Deferred();        setTimeout(function() {          deferred.resolve();        }, 2000);        return deferred.promise();      }    </script></body></html>

 

jquery promise (Deferred)