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

下面的代码显示了Google地图和search结果,当您input地址并点击提交button时。 我一直在玩它试图强制页面完全刷新或重新加载,一旦你点击提交button。 但是我不能正确地工作。 它将结果加载到“页面中”,但是当结果加载时,例如当您点击浏览器上的后退button时,我希望页面完全刷新。 希望是有道理的。

我认为答案在于这一行代码,但我不太了解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() 

编辑:这是另一个例子,一些“jQuery魔术”可以解决问题,而不需要考虑JavaScript的基础知识,这往往是最简单,最快和最直接的方法。

将该行replace为:

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

要么:

 $("#someElement").click(function() { window.location.reload(); }); 

或更好

 window.location.assign("relative or absolute address"); 

这在所有的浏览器和移动设备上都是最好的

添加新事件后,可以通过应用以下代码来刷新事件: – 释放事件 – 设置事件源 – 重新渲染事件

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

这将解决问题

用。。。来代替:

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