es6 - async&await 리셋 제거

2408 단어 HTML5+CSS3
<script src="https://code.jquery.com/jquery-3.1.1.min.js">script>
<script type="text/javascript">
async function ajax(url) {
    return new Promise(function (resolve, reject) {
        let ajaxSetting = {
            url: url,
            dataType: 'text',
            success: function (response) {
              resolve(response);
            },
            error: function (e) {
                console.log(e);
                reject(" ");
            }
        }
        $.ajax(ajaxSetting);

    });
}
async function run() {
  try{
    let response1 = await ajax("text1.json");
    //console.log(response1);
    let response2 = await ajax("text2.json");
    console.log(response1);
    console.log(response2);
  }catch(e){
    console.log(e);
  }
}
$(function(){
  run();
});


script>

좋은 웹페이지 즐겨찾기