0
I’m trying to make a read on JSON, and it turns out what I wish on a div but my console is returned the following error,
XMLHttpRequest cannot load
JSON file:
{"content":{"nome":"Josimara","pais":"brasil"}}
HTML
<script type="text/javascript">
$(function() {
$.get("arquivo/json", { },
function(data){
$("#nome").html(data.nome);
}, "json");
});
</script>
<div id="nome"></div>
What could be this mistake?
So this error is because the URL has no active CORS, that is, it blocks external requests. You can do this ajax on the server?
– Sergio
@Sergio can not do on the server is an external API that I get the information, what would be the best solution for this case?
– Josimara
This API supports JSONP?
– Sergio
@Josimara, could you tell us what the
API
? the point is, she’s probably blocking access by not having theCORS
active (as Rgio spoke), and theJSONP
would be an alternative to "bypass" the problem– Rafael Augusto
@Josimara, if you could pass the link, it would help
– Rafael Augusto
@Rafaelaugusto Can yes of course, https://help.trustedcompany.com/hc/pt-br/articles/115000861763-API-Dados-de-classifica%C3%A7%C3%A3o-da-loja and https://help.trustedcompany.com/hc/pt-br/articles/213341086-Bestseu-CTR-em-resultados-org%C3%A2nicos-using-Rich-Snippets
– Josimara
@Josimara Your Keys are right? This may be influencing problem with
CORS
– Rafael Augusto
Yes @Rafaelaugusto correct, because if it doesn’t generate json
– Josimara
@Rafaelaugusto the API company is doing a check on their server to see if CORS is enabled, let’s wait :)
– Josimara
@Josimara When they do, tell us how it went ;)
– Rafael Augusto