脚本可以在本地主机上运行,​​但不能在服务器上运行

2023-12-01

我遇到这个问题,代码在本地主机上运行,​​但当我将其上传到服务器时却不起作用。

我想实现这个:宝丽莱照片吧画廊

这是我的网站的链接:十二生肖 2013

Note:您需要进入图库选项卡才能查看它。

EDIT:请使用 Google Chrome 浏览器观看以获得最佳观看体验。

我尝试使用 FireBug 但没有帮助。通过google chrome的Inspect Element功能,我发现服务器不接受编写的javascript代码文档内。代码有点庞大,涉及很多文件,以下是主要的:

HTML 标记

<h1>Polaroid Photobar Gallery</h1>
    <div id="pp_gallery" class="pp_gallery">

        <div id="pp_loading" class="pp_loading"></div>
        <div id="pp_next" class="pp_next"></div>
        <div id="pp_prev" class="pp_prev"></div>
        <div id="pp_thumbContainer">

            <div class="album">
                <div class="content">
                    <img src="../images/album1/thumbs/1.jpg" alt="../images/album1/1.jpg" />
                    <span>The Sixties by Tetsumo</span>
                </div>
                <div class="content">
                    <img src="../images/album1/thumbs/2.jpg" alt="../images/album1/2.jpg" />
                    <span>The Sixties by Tetsumo</span>
                </div>
                <div class="content">
                    <img src="../images/album1/thumbs/3.jpg" alt="../images/album1/3.jpg" />
                    <span>The Sixties by Tetsumo</span>
                </div>
                <div class="content">
                    <img src="../images/album1/thumbs/4.jpg" alt="../images/album1/4.jpg" />
                    <span>The Sixties by Tetsumo</span>
                </div>
                <div class="content">
                    <img src="../images/album1/thumbs/5.jpg" alt="../images/album1/5.jpg" />
                    <span>The Sixties by Tetsumo</span>
                </div>
                <div class="content">
                    <img src="../images/album1/thumbs/6.jpg" alt="../images/album1/6.jpg" />
                    <span>The Sixties by Tetsumo</span>
                </div>
                <div class="descr">
                    The Sixties
                </div>
            </div>

            <div class="album">
                <div class="content">
                    <img src="../images/album2/thumbs/1.jpg" alt="../images/album2/1.jpg" />
                    <span>Butterfly Girl</span>
                </div>
                <div class="content">
                    <img src="../images/album2/thumbs/2.jpg" alt="../images/album2/2.jpg" />
                    <span>Mmmmmmh Strawberries</span>
                </div>
                <div class="content">
                    <img src="../images/album2/thumbs/3.jpg" alt="../images/album2/3.jpg" />
                    <span>Polaroid in Picture</span>
                </div>
                <div class="content">
                    <img src="../images/album2/thumbs/4.jpg" alt="../images/album2/4.jpg" />
                    <span>Girl with brown hair</span>
                </div>
                <div class="content">
                    <img src="../images/album2/thumbs/5.jpg" alt="../images/album2/5.jpg" />
                    <span>Hair up</span>
                </div>
                <div class="content">
                    <img src="../images/album2/thumbs/6.jpg" alt="../images/album2/6.jpg" />
                    <span>Smiling Girl</span>
                </div>
                <div class="descr">
                    Portraits
                </div>
            </div>

            <div id="pp_back" class="pp_back">Albums</div>
        </div>
    </div>
    <div>
        <span class="reference">
            <a href="http://tympanus.net/codrops/2010/09/28/polaroid-photobar-gallery/">back to the Codrops tutorial</a>
        </span>
    </div>

THE CSS

.pp_loading{
display:none;
position:fixed;
top:50%;
left:50%;
margin:-35px 0px 0px -35px;
background:#fff url(../images/icons/loader.gif) no-repeat center center;
width:70px;
height:70px;
z-index:999;
opacity:0.7;
-moz-border-radius:10px;
-webkit-border-radius:10px;
border-radius:10px;
}
.pp_next, .pp_prev{
cursor:pointer;
top:50%;
margin-top:-16px;
width:32px;
height:32px;
position:fixed;
text-align:center;
border:1px solid #111;
color:#fff;
-moz-box-shadow:0px 0px 3px #000;
-webkit-box-shadow:0px 0px 3px #000;
box-shadow:0px 0px 3px #000;
}
.pp_next{
right:-40px;
background:#222 url(../images/icons/next.png) no-repeat center center;
}
.pp_prev{
left:-40px;
background:#222 url(../images/icons/prev.png) no-repeat center center;
}
#pp_thumbContainer{
position:fixed;
bottom:0px;
left:0px;
height:65px;
width:100%;
}
#pp_thumbContainer .album{
position:absolute;
width:200px;
height:65px;
bottom:-90px;
}
.album .descr,
.pp_back{
position:absolute;
bottom:0px;
left:-16px;
background:#222;
text-align:center;
border:1px solid #111;
padding:5px;
cursor:pointer;
width:169px;
color:#fff;
cursor:pointer;
text-shadow:0px 0px 1px #fff;
-moz-box-shadow:1px 1px 4px #000;
-webkit-box-shadow:1px 1px 4px #000;
box-shadow:1px 1px 4px #000;
}
.pp_back{
text-transform:uppercase;
bottom:120px;
left:-100px;
width:80px;
}
#pp_thumbContainer .content{
position:absolute;
top:0px;
height:155px;
cursor:pointer;
}
#pp_thumbContainer img{
border:5px solid #fff;
-moz-box-shadow:1px 1px 7px #000;
-webkit-box-shadow:1px 1px 7px #000;
box-shadow:1px 1px 7px #000;
}
#pp_thumbContainer .content span{
display:none;
}
.pp_preview{
position:fixed;
top:150%;
left:50%;
}
.pp_preview img{
position:absolute;
top:0px;
left:0px;
border:10px solid #fff;
border-bottom:45px solid #fff;
-moz-box-shadow:1px 1px 7px #000;
-webkit-box-shadow:1px 1px 7px #000;
box-shadow:1px 1px 7px #000;
}
.pp_descr{
height:45px;
line-height:45px;
font-size:28px;
width:100%;
bottom:0px;
left:0px;
position:relative;
text-align:center;
color:#fff;
}
h1{
            font-size:50px;
            margin:50px;
            color:#333;
        }
        span.reference{
            font-family:Arial;
            position:fixed;
            right:10px;
            top:10px;
            font-size:15px;
        }
        span.reference a{
            color:#fff;
            text-transform:uppercase;
            text-decoration:none;
        }

上面的代码包含在名为 style1.css 的外部文件中。你可以在我的网站上找到它。 最后,JavaScript:

 $(function() {
            var ie          = false;
            if ($.browser.msie) {
                ie = true;
            }
            //current album/image displayed 
            var enableshow  = true;
            var current     = -1;
            var album       = -1;
            //windows width
            var w_width     = $(window).width();
            //caching
            var $albums     = $('#pp_thumbContainer div.album');
            var $loader     = $('#pp_loading');
            var $next       = $('#pp_next');
            var $prev       = $('#pp_prev');
            var $images     = $('#pp_thumbContainer div.content img');
            var $back       = $('#pp_back');

            //we wnat to spread the albums through the page equally
            //number of spaces to divide with:number of albums plus 1
            var nmb_albums  = $albums.length;
            var spaces      = w_width/(nmb_albums+1);
            var cnt         = 0;
            //preload all the images (thumbs)
            var nmb_images  = $images.length;
            var loaded      = 0;
            $images.each(function(i){
                var $image = $(this);
                $('<img />').load(function(){
                    ++loaded;
                    if(loaded == nmb_images){
                        //let's spread the albums equally on the bottom of the page
                        $albums.each(function(){
                            var $this   = $(this);
                            ++cnt;
                            var left    = spaces*cnt - $this.width()/2;
                            $this.css('left',left+'px');
                            $this.stop().animate({'bottom':'0px'},500);
                        }).unbind('click').bind('click',spreadPictures);
                        //also rotate each picture of an album with a random number of degrees
                        $images.each(function(){
                            var $this   = $(this);
                            var r       = Math.floor(Math.random()*41)-20;
                            $this.transform({'rotate'   : r + 'deg'});
                        });
                    }
                }).attr('src', $image.attr('src'));
            });

            function spreadPictures(){
                var $album  = $(this);
                //track which album is opened
                album       = $album.index();
                //hide all the other albums
                $albums.not($album).stop().animate({'bottom':'-90px'},300);
                $album.unbind('click');
                //now move the current album to the left 
                //and at the same time spread its images through 
                //the window, rotating them randomly. Also hide the description of the album

                //store the current left for the reverse operation
                $album.data('left',$album.css('left'))
                      .stop()
                      .animate({'left':'0px'},500).find('.descr').stop().animate({'bottom':'-30px'},200);
                var total_pic   = $album.find('.content').length;
                var cnt         = 0;
                //each picture
                $album.find('.content')
                      .each(function(){
                    var $content = $(this);
                    ++cnt;
                    //window width
                    var w_width     = $(window).width();
                    var spaces      = w_width/(total_pic+1);
                    var left        = (spaces*cnt) - (140/2);
                    var r           = Math.floor(Math.random()*41)-20;
                    //var r = Math.floor(Math.random()*81)-40;
                    $content.stop().animate({'left':left+'px'},500,function(){
                        $(this).unbind('click')
                               .bind('click',showImage)
                               .unbind('mouseenter')
                               .bind('mouseenter',upImage)
                               .unbind('mouseleave')
                               .bind('mouseleave',downImage);
                    }).find('img')
                      .stop()
                      .animate({'rotate': r+'deg'},300);
                    $back.stop().animate({'left':'0px'},300);
                });
            }

            //back to albums
            //the current album gets its innitial left position
            //all the other albums slide up
            //the current image slides out
            $back.bind('click',function(){
                $back.stop().animate({'left':'-100px'},300);
                hideNavigation();
                //there's a picture being displayed
                //lets slide the current one up
                if(current != -1){
                    hideCurrentPicture();
                }

                var $current_album = $('#pp_thumbContainer div.album:nth-child('+parseInt(album+1)+')');
                $current_album.stop()
                              .animate({'left':$current_album.data('left')},500)
                              .find('.descr')
                              .stop()
                              .animate({'bottom':'0px'},500);

                $current_album.unbind('click')
                              .bind('click',spreadPictures);

                $current_album.find('.content')
                          .each(function(){
                            var $content = $(this);
                            $content.unbind('mouseenter mouseleave click');
                            $content.stop().animate({'left':'0px'},500);
                            });

                $albums.not($current_album).stop().animate({'bottom':'0px'},500);
            });

            //displays an image (clicked thumb) in the center of the page
            //if nav is passed, then displays the next / previous one of the 
            //current album
            function showImage(nav){
                if(!enableshow) return;
                enableshow = false;
                if(nav == 1){
                    //reached the first one
                    if(current==0){
                        enableshow = true;
                        return;
                    }
                    var $content            = $('#pp_thumbContainer div.album:nth-child('+parseInt(album+1)+')')
                                              .find('.content:nth-child('+parseInt(current)+')');
                    //reached the last one
                    if($content.length==0){
                        enableshow = true;
                        current-=2;
                        return;
                    }   
                }
                else
                    var $content            = $(this);

                //show ajax loading image
                $loader.show();

                //there's a picture being displayed
                //lets slide the current one up
                if(current != -1){
                    hideCurrentPicture();
                }

                current                 = $content.index();
                var $thumb              = $content.find('img');
                var imgL_source         = $thumb.attr('alt');
                var imgL_description    = $thumb.next().html();
                //preload the large image to show
                $('<img style=""/>').load(function(){
                    var $imgL   = $(this);
                    //resize the image based on the windows size
                    resize($imgL);
                    //create an element to include the large image
                    //and its description
                    var $preview = $('<div />',{
                        'id'        : 'pp_preview',
                        'className' : 'pp_preview',
                        'html'      : '<div class="pp_descr"><span>'+imgL_description+'</span></div>',
                        'style'     : 'visibility:hidden;'
                    });
                    $preview.prepend($imgL);
                    $('#pp_gallery').prepend($preview);

                    var largeW              = $imgL.width()+20;
                    var largeH              = $imgL.height()+10+45;
                    //change the properties of the wrapping div 
                    //to fit the large image sizes
                    $preview.css({
                        'width'         :largeW+'px',
                        'height'        :largeH+'px',
                        'marginTop'     :-largeH/2-20+'px',
                        'marginLeft'    :-largeW/2+'px',
                        'visibility'    :'visible'
                    });
                    Cufon.replace('.pp_descr');
                    //show navigation
                    showNavigation();

                    //hide the ajax image loading
                    $loader.hide();

                    //slide up (also rotating) the large image
                    var r           = Math.floor(Math.random()*41)-20;
                    if(ie)
                        var param = {
                            'top':'50%'
                        };
                    else
                        var param = {
                            'top':'50%',
                            'rotate': r+'deg'
                        };
                    $preview.stop().animate(param,500,function(){
                        enableshow = true;
                    });
                }).error(function(){
                    //error loading image. Maybe show a message : 'no preview available'?
                }).attr('src',imgL_source); 
            }

            //click next image
            $next.bind('click',function(){
                current+=2;
                showImage(1);
            });

            //click previous image
            $prev.bind('click',function(){
                showImage(1);
            });

            //slides up the current picture
            function hideCurrentPicture(){
                current = -1;
                var r   = Math.floor(Math.random()*41)-20;
                if(ie)
                    var param = {
                        'top':'-150%'
                    };
                else
                    var param = {
                        'top':'-150%',
                        'rotate': r+'deg'
                    };
                $('#pp_preview').stop()
                                .animate(param,500,function(){
                                    $(this).remove();
                                });
            }

            //shows the navigation buttons
            function showNavigation(){
                $next.stop().animate({'right':'0px'},100);
                $prev.stop().animate({'left':'0px'},100);
            }

            //hides the navigation buttons
            function hideNavigation(){
                $next.stop().animate({'right':'-40px'},300);
                $prev.stop().animate({'left':'-40px'},300);
            }

            //mouseenter event on each thumb
            function upImage(){
                var $content    = $(this);
                $content.stop().animate({
                    'marginTop'     : '-70px'
                },400).find('img')
                      .stop()
                      .animate({'rotate': '0deg'},400);
            }

            //mouseleave event on each thumb
            function downImage(){
                var $content    = $(this);
                var r           = Math.floor(Math.random()*41)-20;
                $content.stop().animate({
                    'marginTop'     : '0px'
                },400).find('img').stop().animate({'rotate': r + 'deg'},400);
            }

            //resize function based on windows size
            function resize($image){
                var widthMargin     = 50
                var heightMargin    = 200;

                var windowH      = $(window).height()-heightMargin;
                var windowW      = $(window).width()-widthMargin;
                var theImage     = new Image();
                theImage.src     = $image.attr("src");
                var imgwidth     = theImage.width;
                var imgheight    = theImage.height;

                if((imgwidth > windowW)||(imgheight > windowH)){
                    if(imgwidth > imgheight){
                        var newwidth = windowW;
                        var ratio = imgwidth / windowW;
                        var newheight = imgheight / ratio;
                        theImage.height = newheight;
                        theImage.width= newwidth;
                        if(newheight>windowH){
                            var newnewheight = windowH;
                            var newratio = newheight/windowH;
                            var newnewwidth =newwidth/newratio;
                            theImage.width = newnewwidth;
                            theImage.height= newnewheight;
                        }
                    }
                    else{
                        var newheight = windowH;
                        var ratio = imgheight / windowH;
                        var newwidth = imgwidth / ratio;
                        theImage.height = newheight;
                        theImage.width= newwidth;
                        if(newwidth>windowW){
                            var newnewwidth = windowW;
                            var newratio = newwidth/windowW;
                            var newnewheight =newheight/newratio;
                            theImage.height = newnewheight;
                            theImage.width= newnewwidth;
                        }
                    }
                }
                    $image.css({'width':theImage.width+'px','height':theImage.height+'px'});
            }
        });

上面的javascript是写在body部分的代码,浏览器拒绝加载它,因为它是内部代码,FireBug没有帮助。我使用以下几行包含必要的 js 文件(在 head 部分):

<script src="js/jquery.min.js">
</script>

在编写 javascript 代码之前,请在正文部分中执行以下操作:

<script src="js/jquery.transform-0.8.0.min.js"></script>

该画廊在 xampp 服务器上运行时似乎工作正常,但当我将其上传到网络服务器时则不然。请帮我!

Note:我已验证所有文件已成功上传到我的网络服务器上。我是这个网站的新手,所以请原谅我的任何错误并帮助我纠正它们。

EDIT:谷歌浏览器控制台向我显示了许多图像的 404 错误,说它们不存在,但实际上它们确实存在。我也检查了文件夹的权限,一切都很好,猜想这是主要问题。请在这里帮助我。


似乎文件系统在服务器上区分大小写,而在本地计算机上不区分错误。

所有带有小写后缀的图像(*.jpg)可以成功加载,但是上面的(*.JPG)失败(404 未找到)。因为您的代码总是尝试获取小写的图像

在您的网站上:

enter image description here enter image description here

它应该是:

enter image description here

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

脚本可以在本地主机上运行,​​但不能在服务器上运行 的相关文章

  • 为什么我的 css 在 IE9 中无法正确显示?

    几个小时前 我对我的 WordPress 主页做了一个小改动 现在 IE9 中出现了一些以前不存在的随机奇怪 CSS 问题 我曾使用 IE 的开发工具来尝试找出问题所在 但该工具与 firebug 相比实在是太糟糕了 而且问题只出现在 IE
  • PHP curl 获取标头参数

    我将curl 与PHP 结合使用来获取API 调用的标头响应 这是我的代码 curl curl init curl setopt curl CURLOPT URL http localapi com v1 users curl setopt
  • 尝试加载 php_oci8.dll 时 PHP 启动时出现警告

    我正在使用 XAMPP 并尝试为 sql 配置 Oracle 连接 我取消了该行的注释extension php oci8 dll一开始出现错误 缺少oci dll 但后来我从Oracle网页下载了instantclient 我尝试过版本
  • 纯 JavaScript 工具提示

    我正在尝试用纯 JavaScript 制作一个工具提示 显示在hover 就像 Stack Overflow 中将鼠标悬停在个人资料名称 a 上一样div显示 我尝试使用onmouseover onmouseout并添加了setTimeou
  • 将变量从一个 jsp 发送到另一个 jsp

    我有一个 JSP 文件jsp 1 jsp和另一个 JSP 文件jsp 2 jsp 我已经包括了jsp 2 jsp in jsp 1 jsp using 现在我需要某个元素上的单击事件 在该事件中 我想将字符串变量传输到包含的 jsp 中 假
  • 使用 CSS flexbox 重叠两个居中元素

    我试图将两个元素绝对居中于页面中间 一个元素在另一个元素后面 目的是让页面完全响应 中间有一个圆圈 后面有一个脉冲效果 这是一个小提琴 http jsfiddle net Fy8vD 2003 以下的 html body height 10
  • CORS:为什么我的浏览器不发送 OPTIONS 预检请求?

    从我读到的内容来看CORS https en wikipedia org wiki Cross origin resource sharing 我理解它应该按如下方式工作 客户端的脚本尝试获取资源从服务器不同的起源 浏览器拦截这个请求并首先
  • 删除移动设备上的 adsense

    我正在研究响应式设计 但在使用 adsense 时遇到了问题 我有一个广告应该显示在桌面设计上 但不能显示在移动设计上 因此 只有在桌面上查看网站时 才应将广告代码放置在 html 中 css 可以使用 display none 但这违反了
  • 与基线和文本区域垂直对齐

    我试图让标签与文本区域中第一行文本的基线对齐 天真的尝试 div style display inline block div
  • 未捕获的类型错误:无法分配给只读属性

    我正在尝试 Nicholas Zakas 所著的 Professional JavaScript for Web Developers 一书中的这个非常简单的示例 但我不知道我在这里做错了什么 我错过了一些非常简单的事情 但我被困住了 这是
  • 当 JavaScript 抛出异常时不要停止它

    我正在使用 JavaScript 编写一个 Windows 边栏小工具 现在我想捕获所有 JavaScript 异常并将其记录到文本文件中 一个问题是 当任何一行抛出异常时 下一行将不会被执行 是否可以自动捕获异常 以便执行以下 JavaS
  • PayPal REST API:通过重定向 URL 或 Webhook 调用履行订单/付款?

    我正在致力于将 PayPal REST API 集成到我的 Symfony 2 Web 应用程序中 我不确定完成订单 付款的正确时间 地点 与金额 客户数据等其他参数一起 我将两个 URL 传输到 PayPal API 一个是接受付款时用户
  • php 32位日期解析1901年12月13日之前的日期

    我很高兴使用strtotime http www php net manual en function strtotime php在我的开发机器上解析日期 其中一些日期是 1800 年代 一个极端的例子是 1500 年代 但我的开发机是64
  • 比在配置文件中以纯文本形式存储 mysql 密码更好的方法吗?

    许多 PHP 程序要求用户将 mysql 密码以纯文本 字符串或常量 形式存储在应用程序根目录的配置文件中 这一直困扰着我 这么多年过去了 还有更好的方法吗 到目前为止 我已经提出了两个最小的安全提升方案 使用 htaccess 中的规则使
  • 重定向至 2 页

    我有一个 PHP 页面 我想先将其重定向到一个页面 例如 google com 然后再重定向到另一个页面 例如 bing com 为此 我使用以下方法 header Location http google com header Locat
  • Laravel 搜索路由和控制器

    我正在构建我的第一个基本 Laravel Web 应用程序 在学习了一些教程之后 这是我自己修改的第一个应用程序 我在路由到控制器然后获取正确的网址时遇到了一些麻烦 理想情况下 此时我应该只有两条路线 and user 在主页上 您可以通过
  • 什么是标志变量?

    最近我遇到了标志变量 但我不知道它们的作用 我不太确定何时使用标志变量以及如何使用它 我用 Google 搜索了它 但没有任何与我的上下文 JavaScript 相关的具体示例 标记变量的定义和使用 http www javascriptk
  • ImagickException 并显示消息 Postscript delegate 在 MAMP 3.0.5 上失败

    我正在尝试使用 MAMP 3 0 5 将 PDF 转换为 png 文件 我知道我的 PHP 代码可以在我们的 Linux 服务器上正常运行 我在 Mac OSX 10 8 5 上安装了 MAMP 3 0 5 当我运行脚本将 PDF 转换为
  • 错误 1366 (HY000):整数值不正确:第 1 行的列“id”的“”[已关闭]

    Closed 这个问题需要调试细节 help minimal reproducible example 目前不接受答案 My code sql INSERT INTO static table name sql join array key
  • 当我在对象上调用函数时,为什么会在非对象上出现此函数调用错误? [复制]

    这个问题在这里已经有答案了 Error 致命错误 调用成员函数 中的非对象上的bind param var www web55 web pdftest events php 76号线 Code public function countDa

随机推荐