Code runs fine in .html, but not in blogspot.com

55 Views Asked by At

I’m trying to get a value from a JSONP address and show it in a new line of text. The script runs fine in .html (saving to .html and opening in desktop), but it doesn’t work when posting to a blog (blogspot.com).

I’ve already seen an answer here based on functions that make the code load only after the document has finished loading, but my code already has that function, and it doesn’t work anyway.

Also, I know blogspot.com allows javascript and jquery from my own experience.

Doesn’t it allow ajax requests? I haven’t seen such a statement on the web.

Any help is appreciated.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>
$(document).ready(function(){
  $("button#butt").click(function(){
    $("#div1").load("http://api.sidra.ibge.gov.br/values/t/1419/n1/all/h/n/v/69/p/last%201?formato=json", function(data) {
        var json = data, obj = JSON.parse(json);
        $("#div1").text(obj[0].V);
    });
  });
});
</script>

<div id='div1'></div>
<button id="butt">Show value</button>
1

There are 1 best solutions below

0
rnahumaf On

As mentioned by Felipe Gonçalves Marques in the comments above, one of the URLs wasn't HTTPs, which made it incompatible with the webpage, since it uses the HTTPs protocol by default. I fixed it by deselecting the automatic HTTPs redirection in Blogger's settings.