无限循环 - Jquery插件(地址)

时间:2011-06-20 11:18:41

标签: javascript jquery-plugins jquery infinite-loop

我正在使用当前的jQuery插件(地址),我有这个代码(我正在使用地址插件的“SEO”方法)

$(document).ready(function() {
    $.address.crawlable(1).state('/').init(function() {
        $('body').delegate('.ajax', 'click', function() {
            $('.ajax').address();
        });
        $('.ajax').address();
    }).change(function(e) {
        var loc = document.location.href;
        if (loc != 'http://secret.riseofkings.net' + e.value) {
            var myStr = e.value;
            myStr = myStr.substr(1);
            if (myStr) {

                $("#content").html('<img src="/images/ajax.gif" />');
                $("#iframe_space").html('<iframe src="http://riseofkings.net/nothing.php" style="display:none"></iframe>');
                var url = $(e).val().toLowerCase().substr(1).replace(/ /g, '%20');
                $("#content").load(url + '&ajax=1', function() {
                    $("#iframe_space").html('');
                }, function(errr) {
                    alert('Something went wrong. Sorry for problems');
                });
            }
        }
    });
});

更新:

当我尝试添加

alert(loc+' vs http://<?php echo $security->host()."'"; ?>+e.value);

if (loc != 'http://secret.riseofkings.net' + e.value) {

它给了我http://secret.riseofkings.net/game.php vs http://secret.riseofkings.net/ 当我转到链接(/game.php?what=map)时,它会提醒http://secret.riseofkings.net/game.phphttp://secret.riseofkings.net/game.php?what=map

ENDUPDATE;

UPDATE2:

这种情况正在发生,例如在Mozilla/5.0 (Windows; U; Windows NT 5.1; cs; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2

ENDUPDATE;

但在某些Firefox版本(3.XX)和IE中存在无限循环。我访问主页面,它开始重新加载并将#/game.php?r=something附加到地址栏中的地址末尾。

你不知道那里有什么问题吗?

2 个答案:

答案 0 :(得分:1)

这一行:

clearTimeout = window.clearTimeout(timer);

错了,可怕;应该只是:

clearTimeout(timer);

答案 1 :(得分:0)

我在asp.net MVC网站上遇到了与JQuery Address类似的问题。如果我点击回到带有哈希网址的页面,它会发疯并无休止地循环页面。事实证明,该问题与mvc标准的旧版MicrosoftAjax.js和MicrosoftAjax.debug.js文件有关。

如果您打开MicrosoftAjax.debug.js文件并看到FileVersion:4.0.20526.0(这是mvc模板的默认版本),那么从cdn(http://www.asp.net/ajaxlibrary/CDNAjax4.ashx)<升级调试版和压缩版/ p>

请注意这个解决方案是在堆栈溢出的另一个问题中找到的,所以它不是我的解决方案。我试图找到原始问题,谁给出了解决方案。

编辑:Firefox 6 Infinite Page Refresh With Page With Hash Tags