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

Javascript 如何在jQuery中强制页面刷新或重新加载?,javascript,jquery,google-maps,refresh,reload,Javascript,Jquery,Google Maps,Refresh,Reload,当您输入地址并点击提交按钮时,下面的代码显示谷歌地图和搜索结果。我一直在玩它来尝试 并在点击提交按钮后强制页面完全刷新或重新加载。但我不能让它正常工作。它会在“页面”中加载结果,但我希望在加载结果时页面会完全刷新,比如当您点击浏览器上的“后退”按钮时。希望这是有道理的 我认为答案在于这一行代码,但我对jquery不是很了解。它在下面完整代码的底部 <script type="text/javascript"> (function($) { $(document).ready

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

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

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

(函数($){
$(文档).ready(函数(){
加载();';
下面是完整的代码。任何帮助都将不胜感激

<?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()

将该行替换为:

$("#someElement").click(function() {
    window.location.href = window.location.href;
});
或:

或者更好

window.location.assign("relative or absolute address");
这在所有浏览器和移动设备上都能发挥最佳效果

替换为:

$('#something').click(function() {
    location.reload();
});

通过应用以下代码,可以在添加新事件后刷新事件: -发布事件 -设置事件源 -重新渲染事件

  $('#calendar').fullCalendar('removeEvents');
                  $('#calendar').fullCalendar('addEventSource', YoureventSource);         
                  $('#calendar').fullCalendar('rerenderEvents' );

这会解决问题的

嘿,谢谢大家。我对这方面完全不在行,但当我用window.location.reload()替换load();页面加载时会不断刷新,而且不会停止。你能告诉我在哪里进行更改吗?onsubmit=“searchLocations(\'.$categories.\”);return false;“摆脱“return false”。谢谢,但我仍然处于无限刷新循环中。我做得对吗:(function($){$(document).ready(function(){window.location.reload());”;这是因为每次加载页面时,DOM准备就绪后会再次刷新。基本上,您希望将其绑定到某个元素的click方法。请参阅更新后的答案。如果该元素恰好是一个链接,则在事件处理程序的结尾处,
返回false
。@TimMac-请参阅我的编辑,您将需要包含整个代码精简文档准备就绪:
$(“#someElement”)。单击(function(){window.location.href=window.location.href;})
根据语法,那不是:window.parent.window.location.reload()?我检查了MozDevNet,发现“窗口通常无法通过父窗口访问,您必须使用以下属性:window.opener.locaten.reload()Well window.parent已返回对父窗口的引用,因为父窗口的类型为window。在我的情况下,window.location.reload()会破坏我的代码,window.parent.location.reload()会导致浏览器页面执行以下操作。”“闪光灯”效果。我正在尝试更新Twitter提要,当我更改主题(“屏幕名称”)时,我希望新的推文替换旧的推文。请使用window.location.reload(true);否则,如果缓存已经在缓存中,将使用缓存。
  $('#calendar').fullCalendar('removeEvents');
                  $('#calendar').fullCalendar('addEventSource', YoureventSource);         
                  $('#calendar').fullCalendar('rerenderEvents' );