Promise use in order to obtain content using ajax three txt file in the same directory on the server

< Script > 
        // custom function content acquired using three Promise using ajax txt file in the same directory on the server in order, and display them in the console log 
        function getPromise (URL) {
             var P =  new new Promise ( function (Resolve , Reject) {
             var Conn =  new new the XMLHttpRequest () 
            conn.Open ( " GET " , URL, to true ) 
            conn.onload =  function () {
                 IF ( the this .status > = 200 is  && conn.status < 300) { 
                    Resolve ( the this .responseText) 
                } the else { 
                    Reject ( the this .responseText) 
                } 
            } 
            conn.send () 
        }) 
        return P 
     } 
    // individually then acquires information txt method, then a return in each set to a value with txt file to adjust the content of the new Promise instance, it is possible to continuously call the then 
     getPromise ( " ./text1.txt " ) .then ( function (Data) { 
        the console.log (Data) 
        return getPromise ( " ./text2.txt " ) 
     }). the then ( function(data){
        console.log(data)
        return getPromise("./text3.txt")
     }).then(function(data){
            console.log(data)})

    </script>

 

Guess you like

Origin www.cnblogs.com/wangbingblog/p/11572661.html