9
I need to get content from another page inside the site using Javascript, I tried using ajax, but gives this error "Blocked cross-origin request: The same origin policy (Same Origin Policy) prevents reading the remote resource on https://www.google.com/. (Reason: CORS header 'Access-Control-Allow-Origin' is not present)."
I need to take the value of some Divs and put in variables, I need to do this using Javascript.
How to do this?
Code used:
function showUser(str) {
if (str == "") {
document.getElementById("cabecalho").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("cabecalho").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","https://www.google.com");
xmlhttp.send();
}
}
showUser("str");
I’m guessing you don’t control the server that hosts that content, right? You control a server where you can install e.g. a PHP script, which can request the server with the contents?
– user25930
No, I can only include HTML, Javascript and CSS code.
– Felipe Jorge
You mentioned in another comment that this is for an online store. The store already has HTTPS on?
– user25930
I found that I can only import pages from the site itself if I try to import google for example does not work. (Not even any other site)
– Felipe Jorge
Still need to import file from another page, help me. Nothing works...
– Felipe Jorge
from my point of view the only way to make this request is by consuming a Webservice/API of the site in question, if there is no such feature on the site it is not possible to obtain the data with language limitations
– Pedro Sanção
There is no way to get information from another page just with Javascript?
– Felipe Jorge
@Felipejorge I left an example there in my reply, it runs until here in the OS, type any address in the demonstration there that already comes out the result right there
– SneepS NinjA