'Grtting Error of CORS to get data Using Fetch for GET API [duplicate]

Error of CORS if we use mode:"no-cors" than nothing happens

Code :

    fetch(
      "http://url")
      .then(function (response) {
        if (!response.ok) {
          throw new Error("HTTP error, status = " + response.status);
        }
        return response.json();
      })
      .then(function (json) {
        console.log(json);
      })
      .catch(function (error) {
        console.log("Error: " + error.message);
      });


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source