JavaScript හි සමමුහුර්ත විලාසයේ fetch

ඔබට සමමුහුර්ත විලාසයෙන් fetch සමඟ ද වැඩ කළ හැකිය:

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

පහත කේතය සමමුහුර්ත විලාසයට යළි ලියන්න:

javascriptbutton.addEventListener('click', function() {
  let promise = fetch('/ajax.html')
  .then(
    response => {
      if (response.ok) {
        return response.text();
      } else {
        throw new Error('පිළිතුරේ නරක තත්වය');
      }
    },
  ).then(
    text => {
      console.log(text);
    }
  ).catch(
    error => {
      console.log(error);
    }
  );
});