When the application requested another application placed on a different server. your browser doesn’t allow the request due to a security issue.
There is some way to get the data from another application page or API for this we need to use the proxy URL.
let’s see the example:-
/* cors-anywhere - This API enables cross-origin requests to anywhere.*/
const proxyurl = "https://cors-anywhere.herokuapp.com/";
/* Request Url */
// const requestUrl = "http://pollaweb.com/nmr/playingnow.txt";
const requestUrl = "https://www.programiz.com/wp-content/themes/programiz";
/* Requesting the Request URL Using the ProxyUrl */
$( document ).ready(function() {
$(".status").html("Please be patient we are preparing the request Data for you!");
});
fetch(proxyurl + requestUrl)
.then(res => {
var parent = [];
res.text().then((pollawebData)=>{
var dataArr = pollawebData.split("\n");
var child = [];
dataArr.forEach(function(entry) {
parent.push(entry.split("-"))
});
console.log(parent);
$(".status").html("Done Plase check the Console.");
})
})
.catch(() => {
console.log("Can’t access " + requestUrl + " response. Blocked by browser?");
})
Hello Friends, I’m Mohit Sharma founder of tutrialwala.com, Full Stack Web Developer. Expertise in WordPress, PHP, Laravel, Angular, and Frontend Development. In this publication, I share everything I know about PHP frameworks and Javascript frameworks, packages, and tools.
Have a project in mind? Get in touch