javascript - 如何在 jQuery 中强制刷新或重新加载页面?

标签 javascript jquery google-maps refresh reload

当您输入地址并点击提交按钮时,下面的代码会显示 Google map 和搜索结果。我一直在玩它来尝试 并在您点击提交按钮后强制页面完全刷新或重新加载。但我无法让它正常工作。它“在页面中”加载结果,但我希望页面在结果加载时完全刷新,就像您点击浏览器上的后退按钮一样。希望这是有道理的。

我认为答案就在这行代码中,但我对 jquery 不是很了解。它位于下面完整代码的底部附近。

<script type="text/javascript">
(function($) { 
    $(document).ready(function() {
        load();';

下面是完整的代码。任何帮助将不胜感激!

<?php
/*
SimpleMap Plugin
display-map.php: Displays the Google Map and search results
*/
$to_display = '';

if ($options['display_search'] == 'show') {
$to_display .= '
<div id="map_search" style="width: '.$options['map_width'].';">
    <a name="map_top"></a>
    <form onsubmit="searchLocations(\''.$categories.'\'); return false;"         name="searchForm" id="searchForm"     action="http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'">
        <input type="text" id="addressInput" name="addressInput" class="address"     />&nbsp;
        <select name="radiusSelect" id="radiusSelect">';

            $default_radius = $options['default_radius'];
            unset($selected_radius);
            $selected_radius[$default_radius] = ' selected="selected"';

            foreach ($search_radii as $value) {
                    $r = (int)$value;
                    $to_display .= '<option valu         e="'.$value.'"'.$selected_radius[$r].'>'.$value.' '.$options['units']."</option>\n";
            }

$to_display .= '    
        </select>&nbsp;
        <input type="submit" value="'.__('Search', 'SimpleMap').'"     id="addressSubmit" class="submit" />
        <p>'.__('Please enter an address or search term in the box above.',     'SimpleMap').'</p>
    </form>
</div>';
}
if ($options['powered_by'] == 'show') {
    $to_display .= '<div id="powered_by_simplemap">'.sprintf(__('Powered by %s     SimpleMap', 'SimpleMap'),'<a href="http://simplemap-plugin.com/"     target="_blank">').'</a></div>';
}

$to_display .= '
<div id="map" style="width: '.$options['map_width'].'; height:     '.$options['map_height'].';"></div>

<div id="results" style="width: '.$options['map_width'].';"></div>

<script type="text/javascript">
(function($) { 
    $(document).ready(function() {
        load();';    

        if ($options['autoload'] == 'some') {
            $to_display .= 'var autoLatLng = new GLatLng(default_lat,     default_lng);
            searchLocationsNear(autoLatLng, autoLatLng.lat() + ", " +     autoLatLng.lng(), "auto", "'.$options['lock_default_location'].'", "'.$categories.'");';
        }

        else if ($options['autoload'] == 'all') {
            $to_display .= 'var autoLatLng = new GLatLng(default_lat,     default_lng);
            searchLocationsNear(autoLatLng, autoLatLng.lat() + ", " +     autoLatLng.lng(), "auto_all", "'.$options['lock_default_location'].'",     "'.$categories.'");';
        }

$to_display .= '
    });
})(jQuery);
</script>';

?>

最佳答案

您不需要 jQuery 来执行此操作。拥抱 JavaScript 的强大功能。

window.location.reload()

关于javascript - 如何在 jQuery 中强制刷新或重新加载页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2803655/

相关文章:

android - 查找两点之间的距离(纬度/经度)

JavaScript - 我的函数在循环中被多次调用时仅触发一次

jquery - jQuery 可以将 ViewModel 发送到 ASP.NET MVC 中的 Controller 吗?

javascript - 使用复选框过滤 Google map 标记

html - 什么是 xml 建议的 url

javascript - 使用 JQuery 动态隐藏/显示 <td>

javascript - 如何在 Node js 中循环异步发送批量邮件?

javascript - 如何使用JS根据选择的选项值更新文本

对象创建中的 JavaScript && 符号

javascript - 检测输入类型 ="date"是否支持占位符