【发布时间】:2021-09-08 10:54:15
【问题描述】:
所以,我正在使用 Django 应用程序,而我也在使用谷歌地图 API。 所以这是实例......当我提交表单时......我只希望我的表单 div 重新加载,而不是我的地图所在的 div。
所以我的代码是...
<section class="middleSection p-2">
<div class="HideOpenMiddleCont justify-content-center" onclick="HideOpenMiddleCont()">
<div class="px-4 rounded-pill bg-warning" id="arrowCont">
<svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" fill="currentColor" class="bi bi-arrow-down-short text-dark" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 4a.5.5 0 0 1 .5.5v5.793l2.146-2.147a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 1 1 .708-.708L7.5 10.293V4.5A.5.5 0 0 1 8 4z"/>
</svg>
</div>
</div>
{% if view == 'trip' %}
{% include "app/passenger/trip.html" %}
{% elif view == "upcomingRides" %}
{% include "app/passenger/upcomingRides.html" %}
{% elif view == "pastRides" %}
{% include "app/passenger/pastRides.html" %}
{% endif %}
<div class="optionBarPull" data-bs-toggle="offcanvas" href="#offcanvasExample" role="button" aria-controls="offcanvasExample">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" class="bi bi-arrow-right-circle-fill" viewBox="0 0 16 16">
<path d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0zM4.5 7.5a.5.5 0 0 0 0 1h5.793l-2.147 2.146a.5.5 0 0 0 .708.708l3-3a.5.5 0 0 0 0-.708l-3-3a.5.5 0 1 0-.708.708L10.293 7.5H4.5z"/>
</svg>
</div>
</section>
<section class="rightSection" id="map">
<h3 class="font3 text-center p-2"><strong>Google Maps is here</strong></h3>
<h4 class="font3 text-center text-danger" id="googleMapsText"></h4>
<h5 class="font3 text-center text-muted">Please try refreshing the page if the maps doesnt display.</h5>
</section>
我的表单在<section class="middleSection p-2"> 中,我想在提交后重新加载,但我想保持<section class="rightSection" id="map"> 原样。
我该如何处理这种情况,因为当我提交表单时,我的所有标记和圆圈都会被删除,这很烦人......
任何帮助将不胜感激!
【问题讨论】:
-
你熟悉 AJAX 吗?您需要使用 JavaScript 和 AJAX 异步提交表单
-
This should get you started,简而言之,使用 Ajax 进行调用,例如到一个专用的端点,得到一个响应,一旦你收到它,用它替换你想要的 div
标签: django