如何强制页面刷新或重新加载jQuery? [英] How to force page refreshes or reloads in jQuery?

查看:208
本文介绍了如何强制页面刷新或重新加载jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

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

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

 <?php 
/ *
SimpleMap插件
display-map.php:显示Google Map和搜索结果
* /
$ to_display =';

if($ options ['display_search'] =='show'){
$ to_display。='
< div id =map_searchstyle =width: '。$ options ['map_width']。';>
< a name =map_top>< / a>
< form onsubmit =searchLocations(\'' 。$ categories.'\'); return false;name =searchFormid =searchFormaction =http://'.$_SERVER ['SERVER_NAME']。$ _ SERVER ['REQUEST_URI']。' >
< input type =textid =addressInputname =addressInputclass =address/>& nbsp;
< select name =radiusSelectid =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'] 。 < /选项> \\\
;
}

$ to_display。='
< / select>& nbsp;
< input type =submitvalue ='.__('Search','SimpleMap')。'id =addressSubmitclass =submit/>
< p>'.__('请在上面的框中输入地址或搜索字词','SimpleMap')。'< / p>
< / form>
< / div>';
}
if($ options ['powered_by'] =='show'){
$ to_display。='< div id =powered_by_simplemap>'。sprintf(__ 'SimpleMap','< a href =http://simplemap-plugin.com/target =_ blank>')。'< / a>< DIV>';


_to_display。='


< div id =resultsstyle =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选项['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()
pre>

The code below displays a Google map and search results when you enter an address and hit the submit button. I've been playing with it to try and force the page to completely refresh or reload once you hit the submit button. But I can't get it to work right. It loads the results "in page," but I'd like the page to completely refresh when the results load, like when you hit the back button on your browser. Hope that makes sense.

I think the answer lies in this line of code but I don't know jquery very well. It's near the bottom of the full code below.

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

Here's the full code below. Any help would be greatly appreciated!

<?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>';

?>

解决方案

You don't need jQuery to do this. Embrace the power of JavaScript.

window.location.reload()

这篇关于如何强制页面刷新或重新加载jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆