简体   繁体   中英

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

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM