V
V
Valery Orlov2019-10-08 12:49:21
JavaScript
Valery Orlov, 2019-10-08 12:49:21

How to make a cross-server GET request from Javascript?

Good day.
Forming a cross-server XMLHttpRequest request:

var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};

request.open('GET', 'https://account.exemple.com/id');
request.send();
}

I encountered an error: Access-Control-Allow-Origin, the essence of which is more or less clear:
the site exemple.com rejects such requests - for the sake of security.
Is it possible somehow to make a cross-server request?
Or at least a JavaScript construct:
window.open("https://account.exemple.com/id", "_blank")

when opening a new browser tab, get the html of the page and pull it out from the following code:
<span data-v-50ca0f34="" data-v-15d61d2e="" class="balance">0,00&nbsp;Р</span>

value 0,00 Р
Jquery code is welcome.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2019-10-08
@lungdesire29

Proxy through your server.
Make a request to yourself, use your server to take the markup from someone else's site, parse and give the necessary values ​​to the front.

L
Lynn "Coffee Man", 2019-10-08
@Lynn

Not unless the site allows it. It is from such cases that CORS protection is made.
PS example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question