-1

I need your help with a strange problem.

The company I work for has a company website. I have been updating pages on their website the last couple of days.

After updating, I decided to upload the website, but suddenly the javascript doesn't work anymore.

I get the following error when I press f12

Uncaught SyntaxError: Invalid or unexpected token

base.js:1 Uncaught ReferenceError: $ is not defined at base.js:1

On the test server (my own server) it works without any problems.

On the main server (company server) it doesn't work.

What could be the issue for this? It's not on just one page, it's on every single page that the Javascript doesn't work.

[update]

I know about the different versions of Javascript. This is already fixed in the testing environment of the company website. This still doesn't fix the current problem.

Thank you

Wesley

SapuSeven
  • 1,252
  • 16
  • 26

4 Answers4

1

It looks like you are using jQuery for your JavaScript code.

The header of the first page contains a tag for loading jQuery:

<script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>

But on the second page, you never load jQuery.

As I don't know how the file structure of your server is, I cannot tell you the exact path, but you need to make sure you load jQuery in a similar way on your company website.

EDIT:

I noticed that you load jQuery from https://www.aska-ltd.jp/js/jquery-1.10.1.min.js. However, this file is not the original file (compared to https://code.jquery.com/jquery-1.10.1.min.js using MD5). If you want to use this old version (not recommended), you can try to re-download it or simply load jQuery in its latest version from its official server (recommended).

SapuSeven
  • 1,252
  • 16
  • 26
1

On the test site you use jQuery 3.3.1:

<script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>

On the main site you use jQuery 1.10.1:

<script src="https://www.aska-ltd.jp/js/jquery-1.10.1.min.js"></script>

Please both use v3 if you don't have specific needs.

NoobTW
  • 2,017
  • 2
  • 19
  • 35
  • I fixed this in the testing environment of the company website. Doesn't fix the problem. – Wesley Schravendijk Aug 22 '18 at 05:10
  • jquery-3.3.1.min.js:2 Uncaught SyntaxError: Invalid or unexpected token swiper.min.js:16 Uncaught SyntaxError: Invalid or unexpected token base.js:1 Uncaught ReferenceError: $ is not defined at base.js:1 fadein.js:24 Uncaught ReferenceError: $ is not defined at fadein.js:24 – Wesley Schravendijk Aug 22 '18 at 05:38
  • In my test, I copy all code from your main site, and simply change "https://www.aska-ltd.jp/js/jquery-1.10.1.min.js" to "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" will work. I still think it's is the jQuery version problem. – NoobTW Aug 22 '18 at 05:49
  • @WesleySchravendijk As you can see from the first line, there is a problem with your jQuery file. It is not original. – SapuSeven Aug 22 '18 at 06:21
0

As @NoobTW and @SapuSeven have said, there is an error in the jQuery script on the production site.

On the production site, try replacing this <script src="https://www.aska-ltd.jp/js/jquery-1.10.1.min.js"></script> with this <script language="JavaScript" type="text/javascript" src="js/jquery-3.3.1.min.js"></script>

Also, if you load jQuery from a CDN, it may help simplify things. Here is one option for jQuery 3: <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha256-3edrmyuQ0w65f8gfBsqowzjJe2iM6n0nKciPUp8y+7E=" crossorigin="anonymous"></script>

See here for more options: https://code.jquery.com/

colefner
  • 1,752
  • 1
  • 15
  • 11
0

JQuery never loads at all on the main server. I tried taking the code from the file on the server and evaluating it, but discovered some sort of corruption in the JQuery file your server is returning:

Chrome Developer Tools showing source of jquery-1.10.1.min.js with strange characters in it and failing to evaluate it in the console because of a SyntaxError.

If the same thing happens with an updated version of JQuery, check whether it’s also corrupted. It may be some sort of transformation the server is incorrectly performing.

Aankhen
  • 1,765
  • 7
  • 17