Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function _fetch(url){
- const response= await fetch(url);
- if (!response.ok){
- const message= `Error: ${response.status}`;
- throw new Error(message);
- }
- const data= await response.clone().json().catch(()=> response.text());
- return data;
- }
- //Calling the function
- let url= "https://kawiesh.duckdns.org";
- _fetch(url)
- .then(d=>{
- let doc= new DOMParser().parseFromString(d,"text/html");
- alert(d);
- //Do something with the received data
- })
- .catch(x=> alert(x.message));
Advertisement
Add Comment
Please, Sign In to add comment