0

I've got an odd situation and can't figure it out why my JavaScripts are not working.

this is the general problem - if I load jquery 2.2.0 from this link: "https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"

it all works fine

however Joomla is loading it's own version 1.2 which I've overridden with my template to current 3.3.1 version

  • at this point things are working but I've got 2 jQuerys loaded (one from joomla and other from google lib)

  • if I remove google 2.2 version, JS is not working (loading with standard script inside html)

  • if I replace jquery in my template with 2.2.0 version from google it is not working still (loading trough joomla head)

I get this error: TypeError: $.tablesorter is undefined

it makes no sense to me

Kyuzo
  • 39
  • 1
  • 1
  • 9
  • I have done some reaserch in the direction Ryan Thompson sugdested but could not find anything that could help me with this situation. I've tried all kinds of combinations between jquery and jquery.migrate scripts with no results. all I can say for now is if version 2.2 is loaded from my server it does not work, but if loaded trough google cdn it works – Kyuzo Jan 03 '19 at 03:28
  • Please post your Joomla questions on Joomla Stack Exchange. – mickmackusa Jan 05 '19 at 12:56
  • thank you for the suggestion, I don't think this is joomla related, anyways I've resolved the issue – Kyuzo Jan 06 '19 at 00:39
  • 1
    Possible duplicate of [How do I change the $ function in jquery for another word for make it compatible with other frameworks](https://stackoverflow.com/questions/1143955/how-do-i-change-the-function-in-jquery-for-another-word-for-make-it-compatible) – mickmackusa Jan 06 '19 at 00:54

3 Answers3

0

Not sure if this will help but I had similar issue on my WordPress website and solved using jQuery Migrate: https://github.com/jquery/jquery-migrate

Usage In your web page, load this plugin after the script tag for jQuery, for example:

<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<script src="https://code.jquery.com/jquery-migrate-3.0.1.js"></script>
Ryan Thompson
  • 105
  • 2
  • 10
  • thnak you, it didn't work out unfortunately, Joomla by default loads jquery migrate, but an old version, I've updated it but with no luck – Kyuzo Jan 02 '19 at 19:34
0

shame, there are a few more ways you could get it working.

So were on same page have you fully removed the Joomla 1.2 jQuery? You mentioned you replaced it with the 3.3.1

also is it a specific page that requires the jQuery 2.2? or are you wanting to move to jQuery 2.2 for the whole site?

if you just need it on one page you could do some php in the header to switch the jQuery used depending on the page URL that way it would only load the required one and not 2 jQuerys on each page. Not the most ideal way but should work.

<?php

//First detect the URL
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

//Now do the if else to switch jQuery on desired page.

if (strpos($url, 'myPage.php') !== false) {
  echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>';
} else {
  echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>';
}

?>

if you need or want it on the latest jQuery i would remove all jQuery and jQuery Migrate then put the latest versions of both in and then try and solve the errors remaining

can you share more errors?

e.g errors with just jQuery 1, then errors with just 2 and so on?

Ryan Thompson
  • 105
  • 2
  • 10
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/21835243) – Larry Shatzer Jan 03 '19 at 14:52
  • I've updated with the answer I suggested, my apologies. – Ryan Thompson Jan 03 '19 at 15:47
  • Thank you for the suggestions, I've done the following and this are the results: - jquery (2.2.0) is loaded trough joomla head along with js.migrate (3.0.1), produce this errors: JQMIGRATE: jQuery 3.0.0+ REQUIRED jquery-migrate.min.js:41:3 JQMIGRATE: Migrate is installed with logging active, version 3.0.1 jquery-migrate.min.js:48:2 TypeError: $ is not a function TypeError: jQuery.event.addProp is not a function *** I get the same error if I use jQuery 1.12 *** If I use 3.3 I get only: "TypeError: $ is not a function" problems is that none JavaScript is working – Kyuzo Jan 05 '19 at 18:47
  • If I load – Kyuzo Jan 05 '19 at 18:50
  • I've removed all instances of other java and jQuery scripts and left only one small jQuery inline script - still getting "TypeError: $ is not a function" – Kyuzo Jan 05 '19 at 20:21
  • Checked if jQuery is loaded(from my server) with this: [link](https://stackoverflow.com/questions/7341865/checking-if-jquery-is-loaded-using-javascript) - getting a positive result – Kyuzo Jan 05 '19 at 20:24
  • I've tried this too: "jQuery(function ($) { ..." same error still – Kyuzo Jan 05 '19 at 20:39
  • Hi Ryan, I was able to resolve this issue, thank you for your suggestions. But I still don't know the exact reason behind this behavior :/ – Kyuzo Jan 05 '19 at 22:57
0

I have managed to resolve the issue by replacing all

$(function () {...

With

jQuery(function ($) { ..

I'm loading latest jQuery from my own server

I have exact same setup on another site and have no such problems

Kyuzo
  • 39
  • 1
  • 1
  • 9