JavaScript တွင် Synchronous Style Fetch

fetch ကို synchronous style နဲ့လည်း အလုပ်လုပ်နိုင်ပါတယ်။

public/client.jsbutton.addEventListener('click', async function() {
  let response = await fetch('/ajax.html');
  let text = await response.text();
  console.log(text);
});
Задание 1

အောက်ပါကုဒ်ကို synchronous style နဲ့ ပြန်ရေးပါ။

javascriptbutton.addEventListener('click', function() {
  let promise = fetch('/ajax.html')
  .then(
    response => {
      if (response.ok) {
        return response.text();
      } else {
        throw new Error('အဖြေရဲ့ status မကောင်းပါ');
      }
    },
  ).then(
    text => {
      console.log(text);
    }
  ).catch(
    error => {
      console.log(error);
    }
  );
});