简体   繁体   English

服务器上传后Javascript无法正常工作

[英]Javascript not working after server upload

Like the title says, I just finished building a website. 就像标题所说的,我刚完成一个网站的建设。 Tested it on my local server where everything works perfectly without any errors. 在我的本地服务器上对其进行了测试,在该服务器上一切正常,没有任何错误。

However, after uploading my files to the dreamhost servers, the site loads but my animations and interactivity are not working. 但是,将我的文件上传到Dreamhost服务器后,该站点已加载,但是我的动画和交互性不起作用。 I contacted the customer service and was told that in my error.log file it says the folder where all my GSAP.js files are located cannot be found. 我联系了客户服务,并被告知在我的error.log文件中找不到所有GSAP.js文件所在的文件夹。 But looking at my panel, all files were uploaded successfully. 但是在我的面板上,所有文件都已成功上传。

In order to be sure it was not just the dreamhost servers, I decided to try uploading the site to github servers and still the same thing. 为了确保它不仅是dreamhost服务器,我决定尝试将该站点上传到github服务器,并且还是一样。 The site and all files uploaded successfuly but the javascript files are not running or located. 该站点和所有文件已成功上传,但是javascript文件未运行或未找到。 I don't know exactly. 我不知道 And after looking at the console and the network in the google developer tools, there is no single error, it shows all files were uploaded successfully as there is no error. 在Google开发人员工具中查看控制台和网络后,没有一个错误,它显示所有文件都已成功上传,因为没有错误。

What may be causing this issue? 是什么导致此问题? I'm lost. 我迷路了。

Here is the code referencing all GSAP.js and my index.js files 这是引用所有GSAP.js和我的index.js文件的代码

<script src="Resources/js/index.js"></script>
<script src="Vendor/js/TweenMax.min.js"></script>
<script src="Vendor/js/Draggable.min.js"></script>
<script src="Vendor/js/ThrowPropsPlugin.min.js"></script>
<script src="Vendor/js/MorphSVGPlugin.min.js"></script>
<script src="Vendor/js/SplitText.min.js"></script>
<script src="Vendor/js/CSSPlugin.js"></script>
<script src="Vendor/js/ScrollToPlugin.js"></script>

Here is my folder structure 这是我的文件夹结构

  • about.html about.html
  • case-studies.html case-studies.html
  • contact.html contact.html
  • contact.php contact.php
  • css folder css文件夹
  • experiments.html Experiment.html
  • images folder 图片文件夹
  • index.html index.html
  • PHPMailer folder PHPMailer文件夹
  • Resources folder 资源文件夹
  • Vendor folder 供应商文件夹

The vendor folder contains all the js files as you can already tell. 如您所知,vendor文件夹包含所有js文件。

All your files loaded correctly .. The problem here 您的所有文件均已正确加载..这里的问题

function setupPage() {
  var url = window.location.pathname;
  var filename = url.substring(url.lastIndexOf('/')+1);
  switch(filename) {
    case 'index.html':
      setupIndex();
      break;
    case 'about.html':
      setupAbout();
      break;
    case 'contact.html':
      setupContact();
      break;
    case 'case-studies.html':
      setupCaseStudies();
      break;
    case 'experiments.html':
      setupsetupExperiments();
      break;
   }
}

you already substring the url to find the page .. but actually you didn't set anything if the url doesn't have any page in url 您已经对网址进行了分substring以查找页面..但实际上,如果该网址中没有任何页面,则您没有设置任何内容

That mean if you go to http://www.seimodei.com/index.html your website will work as expected 也就是说,如果您访问http://www.seimodei.com/index.html,则您的网站将正常运行

so you need to check the filename before switch .. you can use 因此,您需要在切换..之前检查filename

var forcheck = url.substring(url.lastIndexOf('/')+1);
var filename = (forcheck.indexOf('.html') !== 1) ? 'index.html' : forcheck ;

OR redirect to index.html I don't recommend this 或重定向到index.html 我不建议这样做

var forcheck = url.substring(url.lastIndexOf('/')+1);
var filename = 'index.html';
if(forcheck.indexOf('.html') !== 1) {
     window.location.href = "http://www.seimodei.com/index.html";
}else{
     filename = forcheck ;
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM