【问题标题】:Laravel, rendering google address api with ajaxLaravel,用ajax渲染谷歌地址api
【发布时间】:2020-02-26 08:03:47
【问题描述】:

我要渲染google api,如果客户选择送货不提货,这是非常必要的,所以他必须通过填写google地址表单添加他的地址,我现在面临的只是包含google表单时,那么我必须添加脚本链接,这就是我收到错误的原因: 您已在此页面上多次包含 Google Maps JavaScript API。这可能会导致意外错误。 这个问题的最佳解决方案是什么?

googleform.blade:

  <input id="autocomplete" class="addressInput-textInput s-form-control input-overflow" onClick="this.select();" onFocus="geolocate()" type="text" autocapitalize="off" autocorrect="off" autocomplete="off" required=""/>

   <script src="https://maps.googleapis.com/maps/api/js?key=0000&libraries=places&callback=initAutocomplete" defer></script>

jquery:

$.ajax .....

success: function (data) {
            $('#update_order_status').html(data.update_order_status);
        }
    });

控制器:

   $update_order_status = view('include.delivery_information')->render();      
    return Response::json([
        'update_order_status' => $update_order_status,
    ]);   

【问题讨论】:

  • 错误是什么,能否请您附上日志?
  • 添加deliver_information刀片
  • 在该页面的页脚中添加一次此脚本
  • @loic.lopez 我收到错误消息:您在此页面上多次包含 Google Maps JavaScript API。
  • @AmitSharma 也是一样,如果我将它包含在渲染页面之外,google api 表单将永远无法工作

标签: javascript php jquery laravel


【解决方案1】:

问题是因为它多次包含 google API 脚本

中删除callback=initAutocomplete

&lt;script src="https://maps.googleapis.com/maps/api/js?key=0000&amp;libraries=places&amp;callback=initAutocomplete" defer&gt;&lt;/script&gt;

并在on change的内部调用initAutocomplete函数

<input id="autocomplete" class="addressInput-textInput s-form-control input-overflow" onClick="this.select();" onFocus="geolocate()" type="text" autocapitalize="off" autocorrect="off" autocomplete="off" required=""/>

并且只在刀片中添加一次脚本,除了 include.delivery_information

【讨论】:

  • 首先我不知道如何调用 initAutocomplete ,但即使我删除了它仍然得到相同的错误消息
猜你喜欢
  • 1970-01-01
  • 2013-08-07
  • 1970-01-01
  • 1970-01-01
  • 2010-11-12
  • 2014-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多