1
Hello!
I know there are several questions on this subject, but even reading the answers I’m still in trouble. I already tried to put Access-Control-Allow-Origin in the file header. php, I’ve tried to put in virtualhost configuration in Apache as well and nothing seems to work. Where am I going wrong?
I’ve seen that if I use an extension or disable browser flags, it works. So maybe it’s something I’m missing on the client side? :/
Requisição cross-origin bloqueada: A política de mesma origem (Same Origin Policy) impede a leitura do recurso remoto em https://a.4cdn.org/wsg/1.json. (Motivo: o cabeçalho CORS 'Access-Control-Allow-Origin' não está presente).
<html>
<head>
<link rel="stylesheet" href="css/trend.css">
<script src='http://code.jquery.com/jquery-latest.min.js' type='text/javascript'></script>
</head>
<body>
<div class="trendings">
<h3>Trending:</h3>
<div>
<ol id="trending">
</ol>
</div>
</div>
<script>
$(document).ready(function(){
var node,textnode,a,btn;
$.getJSON("https://a.4cdn.org/wsg/1.json", function(json) {
for(var i = 1; i < json.threads.length; i++){
node = document.createElement("li");
a = document.createElement('a');
textnode = document.createTextNode(json.threads[i].posts[0].sub);
a.appendChild(textnode);
a.href="http://boards.4chan.org/wsg/thread/"+json.threads[i].posts[0].no;
document.getElementById("trending").appendChild(node).appendChild(a);
}
});
});
</script>
</body>
</html>
Who should "put the header" is the site you are connecting, in case the
https://a.4cdn.org/wsg/1.json
must have theAccess-Control-Allow-Origin: *
.– Inkeliz
there is something I can do to make this request work?
– dmg Geronimo
CORS was made to not work. What you can do is a Proxying, your website picks up the content and you take this content from your own website.
– Inkeliz
An example of simple "proxying" with Curl: https://answall.com/a/227766/3635
– Guilherme Nascimento