另一个 IE 错误:在使用 jquery 地址或至少使用 ajax 时,第 0 行发生堆栈溢出

发布于 2024-12-05 10:21:41 字数 3721 浏览 5 评论 0原文

各位 stackoverflow 的朋友们大家好, 我构建了一个 ajax 图像库并使用 asual'jquery 地址进行深度链接。 加载图库后,单击图像时的第一次单击或缩略图的所有单击时都会发生错误。

基本上,我在图像上的代码是:

<li id="thumbnail_<?php echo $row->position;?>"><a href="javascript:;" onclick="javascript:setAddress('<?php echo $row->url;?>');"><img src="<?php echo $row->filePath;?>" /></a></li>

我在缩略图上的代码是:

<li id="thumbnail_<?php echo $row->position;?>"><a href="javascript:;" onclick="javascript:setAddress('<?php echo $row->url;?>');"><img src="<?php echo $row->filePath;?>" /></a></li>

这样,当我单击时,我使用 setAddress: 更改地址栏中的地址,

<script type="text/javascript">
    function setAddress(address){ 
        $.address.value(address.replace(/^#/, ''));
    }
</script>

然后检测地址的更改并重新加载图像(并相应地加载缩略图) )在阿贾克斯。

<script type="text/javascript">
    $.address.change(function(event) { 
        checkAnchor();
    }); 

    function checkAnchor(){
        var albumId = <?php echo $albumId;?>;
        if($.address.value() != '' && $.address.value() != '/'){
            //get the id of the image
            var arData = $.address.value().split("-");
            var arIdExt = arData[1].split(".");
            var id = arIdExt[0];
            reloadImage(albumId,id,'0','curr');
        }else{
            reloadImage(albumId,id,'1','curr');
        }
    }

    function reloadImage(albumId, photoId, position, action){
    $("#imgLoading").show();
    var visibleThumbnails = <?php echo $visibleThumbnails;?>;
    var albumName = $("#albumName").val();
    $.post('/montreal/inc/ajax/changeImage.php',{albumId:albumId, photoId:photoId, position:position, action:action}, function(data){
        //data + photoposition=[url]
        var arData = data.split("photoposition=");
        if(position == 0){
            position = jQuery.trim(arData[1]);
        }

        $("#photo-details").html(arData[0]);
        $.address.title(albumName+" - Photo #"+position);
        $("#imgLoading").hide();

        //reload the thumbnails
        if(action == 'next'){               
            var maxThumbnails = <?php echo count($album->arPhotos['photos']);?>;
            var nextPosition = position+1;
            var currentRow = Math.ceil(position/visibleThumbnails);
            if(nextPosition > maxThumbnails){ nextPosition = 1;}                            
            if(position%visibleThumbnails == 0 || position == maxThumbnails){
                reloadThumbnails(currentRow,visibleThumbnails,albumId,nextPosition,'next');
            }else{//fix the activeposition of the reloadThumbnails
                reloadThumbnails(currentRow,visibleThumbnails,albumId,nextPosition,'curr');
            }               
        }else if(action == 'curr'){
            var maxThumbnails = <?php echo count($album->arPhotos['photos']);?>;
            var currentRow = Math.ceil(position/visibleThumbnails);
            reloadThumbnails(currentRow,visibleThumbnails,albumId,position,'curr');
        }
    },"html"  
);

} “第 0 行堆栈溢出”出现在单击之后和 setaddress 之前,因此我很困惑它可能来自哪里。单击错误消息后,没有任何反应,再次单击图像后,图库实际上可以工作。但是,如果我单击缩略图,则会出现错误,但如果再次单击缩略图,错误仍然会出现。

据我所知,这个错误是很常见的,通常是由循环或递归引起的。但我看不到,特别是当我只能在图库中第一次单击时才能看到它发生时。

有人提示我应该在哪里搜索吗?

错误示例: http://www.ckoi.com/montreal/照片/gala-des-gemeaux-tapis-rouge-194/

编辑: 经过一些测试,我意识到错误实际上是在我加载页面后发生的。无论我点击哪里,都会出现堆栈溢出。所以我更困惑了...但也许是因为我第一次用ajax加载图库?我会调查

Hello fellow stackoverflow-ers,
I built an ajax image gallery and used asual' jquery address for the deep linking.
The error happens, right after loading the gallery, on the first onclick when clicking on the image or on all the clicks of the thumbnails.

Basically, my code on the image is:

<li id="thumbnail_<?php echo $row->position;?>"><a href="javascript:;" onclick="javascript:setAddress('<?php echo $row->url;?>');"><img src="<?php echo $row->filePath;?>" /></a></li>

my code on the thumbnails is:

<li id="thumbnail_<?php echo $row->position;?>"><a href="javascript:;" onclick="javascript:setAddress('<?php echo $row->url;?>');"><img src="<?php echo $row->filePath;?>" /></a></li>

so that when I click, I change the address in the address bar using setAddress:

<script type="text/javascript">
    function setAddress(address){ 
        $.address.value(address.replace(/^#/, ''));
    }
</script>

and then I detect the change in the address and reload the image (and thumbnails accordingly) in ajax.

<script type="text/javascript">
    $.address.change(function(event) { 
        checkAnchor();
    }); 

    function checkAnchor(){
        var albumId = <?php echo $albumId;?>;
        if($.address.value() != '' && $.address.value() != '/'){
            //get the id of the image
            var arData = $.address.value().split("-");
            var arIdExt = arData[1].split(".");
            var id = arIdExt[0];
            reloadImage(albumId,id,'0','curr');
        }else{
            reloadImage(albumId,id,'1','curr');
        }
    }

    function reloadImage(albumId, photoId, position, action){
    $("#imgLoading").show();
    var visibleThumbnails = <?php echo $visibleThumbnails;?>;
    var albumName = $("#albumName").val();
    $.post('/montreal/inc/ajax/changeImage.php',{albumId:albumId, photoId:photoId, position:position, action:action}, function(data){
        //data + photoposition=[url]
        var arData = data.split("photoposition=");
        if(position == 0){
            position = jQuery.trim(arData[1]);
        }

        $("#photo-details").html(arData[0]);
        $.address.title(albumName+" - Photo #"+position);
        $("#imgLoading").hide();

        //reload the thumbnails
        if(action == 'next'){               
            var maxThumbnails = <?php echo count($album->arPhotos['photos']);?>;
            var nextPosition = position+1;
            var currentRow = Math.ceil(position/visibleThumbnails);
            if(nextPosition > maxThumbnails){ nextPosition = 1;}                            
            if(position%visibleThumbnails == 0 || position == maxThumbnails){
                reloadThumbnails(currentRow,visibleThumbnails,albumId,nextPosition,'next');
            }else{//fix the activeposition of the reloadThumbnails
                reloadThumbnails(currentRow,visibleThumbnails,albumId,nextPosition,'curr');
            }               
        }else if(action == 'curr'){
            var maxThumbnails = <?php echo count($album->arPhotos['photos']);?>;
            var currentRow = Math.ceil(position/visibleThumbnails);
            reloadThumbnails(currentRow,visibleThumbnails,albumId,position,'curr');
        }
    },"html"  
);

}

The "stack overflow at line 0" appears right after the click and before the setaddress, so that I am pretty confused as to where it could come from. After clicking on the error message, nothing happens, and after clicking on the image again, the gallery actually works. But if I click on the thumbnails, the error appears, but if I click on the thumbnails again, the error still appears.

As far as I've read, this error is way generic and is usually caused by a loop or a recursion. But I cannot see one, especially when I can see it happen only on the first click in the gallery.

Anyone has a hint as to where I should search?

Example of the error:
http://www.ckoi.com/montreal/photos/gala-des-gemeaux-tapis-rouge-194/

EDIT:
After some tests, I realized that the error actually happens right after I loaded my page. Anywhere I click, I get a stack overflow. So that I am even more confused... But maybe it's because I load the gallery a first time in ajax? I'll investigate

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

々眼睛长脚气 2024-12-12 10:21:41

来自原贴:

好的,我找到了。我真的不确定为什么这会给 IE 带来这么大的麻烦,但事实是这样的:

为了跟踪专辑标题并且不必在每次 ajax 调用中获取它,我将它保存在一个不可见的文件中。文本输入:

<input id="albumName" type="text" style="display:none;" value="<?php echo $album->name;?>"/>

如果标题在该隐藏输入中包含双空格,IE 就会抱怨...对我来说,这毫无意义,但现在它有效...

感谢大家的见解!希望这可以帮助其他人调试 IE....

From the original poster:

Ok, I found it. I'm really not sure why this was causing such trouble for IE, but here it was:

In order to keep track of the album title and not to have to get it in every one of my ajax calls, I kept it in an invisible text input :

<input id="albumName" type="text" style="display:none;" value="<?php echo $album->name;?>"/>

If the title had double spaces in that hidden input, IE was complaining... To me, this makes no sense, but now it works...

Thanks guys for your insights! Hopes this helps someone else to debug IE....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文