【问题标题】:Change Embedded Gmaps iFrame SRC using AJAX使用 AJAX 更改嵌入式 Gmaps iFrame SRC
【发布时间】:2018-10-12 18:35:12
【问题描述】:

我正在尝试使用 AJAX 从我的后端数据库中检索到的 URL 来更改 iFrame 的 SRC。我需要通过单击按钮更改地图。

在 iFrame 中显示的错误是“ 404。这是一个错误。 在此服务器上找不到请求的 URL //embed。这就是我们所知道的。”这让我觉得 SRC 没有被正确更改。

在这方面的任何帮助都会很棒!

这是我的设置:

<iframe id="HTMLGmapsSRC" src="" width="300" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>

 var artgmaps = (imagesgmaps[index].replace(/\"/g, ""));
 $('#HTMLGmapsSRC').attr('src', artgmaps);

JSON 响应添加了反斜杠,但是我读过这是正常的吗?

【问题讨论】:

    标签: php html json ajax


    【解决方案1】:

    我用这种方法在 iframe 中嵌入数据。

    $location = "从数据库中获取的地址"。

     <div id="show_map" style="display:block;">
            <address class="row"><?php echo $location;?></address>
      </div>
    

    并使用地址标签显示地图

    $("address").each(function(){ 
    
        var embed ="<iframe width='100%' height='350' frameborder='0' scrolling='no'  marginheight='0' marginwidth='0'   src='https://maps.google.com/maps?&amp;q="+ encodeURIComponent( $(this).text() ) +"&amp;output=embed'></iframe>";
                                        $(this).html(embed);
        });
    

    【讨论】:

    • 我会试一试的:)
    猜你喜欢
    • 2013-07-04
    • 1970-01-01
    • 2011-04-13
    • 2023-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多