Javascript TPL文件中的geoapi

Javascript TPL文件中的geoapi,javascript,prestashop,smarty,Javascript,Prestashop,Smarty,我使用这段代码只为来自英国的客户显示div,它通过内置的页面生成器-prestashop工作 不幸的是,我不能使它在tpl文件的地址形式的工作。 基本上我需要一个地址表下面的文本 <div class="hide GB">text</div> <script type="text/javascript"> {literal} $.get("https://freegeoip.ap

我使用这段代码只为来自英国的客户显示div,它通过内置的页面生成器-prestashop工作

不幸的是,我不能使它在tpl文件的地址形式的工作。 基本上我需要一个地址表下面的文本

    <div class="hide GB">text</div>
    <script type="text/javascript">
    {literal}
    $.get("https://freegeoip.app/json/", function (response) {
    document.getElementsByClassName(response.country_code)[0].style.display = "block";
    }, "jsonp");
    {/literal}
    </script>
文本
{literal}
$.get(”https://freegeoip.app/json/“,功能(响应){
document.getElementsByClassName(response.country_code)[0].style.display=“block”;
}“jsonp”);
{/literal}
我也试过这个:

{literal}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>$.ajax("https://freegeoip.app/json/")
  .done(function (e) {
  $('.hide').eq(e.country_code === 'GB' ? 0 : 1).show();
});</script>
<div class="hide">text</div>
<div id="country_code"></div>
{/literal}
{literal}
$.ajax(”https://freegeoip.app/json/")
.完成(功能(e){
$('.hide').eq(e.country_code==='GB'?0:1).show();
});
文本
{/literal}
他们两人都在拉小提琴。当添加为原始html(不带文本标记ofc)时,它们都可以在页面生成器中工作

但是,由于某些原因,我无法使它们在adrress-form.tpl文件中工作。这篇课文就是看不出来。但是,国家代码显示在我想要的位置。只是文字本身不会。 有什么想法吗? 问候

{literal}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> 
</script>

<div id="GB">text</div>
<script>$.get("https://freegeoip.app/json/", function (response) {
    $("#country_code").html(response.country_code);
    if(response.country_code=='GB'){
        document.getElementById(response.country_code).style.display = "block";
    }
}, "jsonp");</script>


{/literal}
#GB{display:none;}