使用AJAX更改嵌入式Gmaps iFrame SRC

时间:2018-10-12 18:35:12

标签: php html json ajax

我正在尝试使用AJAX从我的后端数据库获取的URL更改iFrame的SRC。我需要单击按钮即可更改地图。

iFrame内显示的错误是“404。那是一个错误。 在此服务器上找不到请求的URL //嵌入。这就是我们所知道的全部。”这使我认为SRC的更改不正确。

任何帮助都会很棒!

这里是我的设置:

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

enter image description here

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

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

1 个答案:

答案 0 :(得分:0)

我使用此方法在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);
    });