+ 3

SoloLearn App: ReferenceError: Can't find variable: $ at Line:

I use jquery in a code like $(function(){…}); in the SoloLearn App. I get the error ReferenceError: Can't find variable: $ at Line:… I get the error by separating the jquery code in the js area. No error is occured by use the js code in the html area with script tag. This behavior is new and only in the mobile SoloLearn App. The error don’t occur in the Webbrowser from SoloLearn. Maybe a bug? Or what is the error? https://code.sololearn.com/WocKD43r40eC

16th Jan 2019, 8:53 PM
asa22
20 ответов
+ 8
asa22 Hey, I don't see any problem at all🙂 I'm using phone with latest android. Maybe you are testing it on older devices (like KrOW 😀😀 Sorry for spam but your name always comes to my mind when I'm testing code on older devices 😀😀)
16th Jan 2019, 9:44 PM
r8w9
r8w9 - avatar
+ 7
KrOW & asa22 Thanks, I was about to post the same question. I'm on iOS and had always found the same error reviewing codes from other SoloLearners.
28th Jan 2019, 3:36 AM
Geovanny Martínez Forero
Geovanny Martínez Forero - avatar
+ 5
asa22 No "JS Content" is printed? 😕 Anyway it seem like a bug. it works differently from android which execute at last the js tab content (like Ipang said). A fast half-solution is execute your js code on window load like: window.load= function(){ $('p').click(...); } to be sure that js is loaded
17th Jan 2019, 8:05 PM
KrOW
KrOW - avatar
+ 5
asa22 I want inform you that the problem would be solved in the next-upcoming iOS release... Feel free to inform me if it will work (or not) when you will update the app (i dont know the date of next release but it not would be far) 😉
18th Jan 2019, 2:07 PM
KrOW
KrOW - avatar
+ 4
r8w9 😂😂😂. Dont worry, my device "incompatibility" getting popularity 😁 asa22 The code that you linked show the error to you?
16th Jan 2019, 10:05 PM
KrOW
KrOW - avatar
+ 4
KrOW and xpnvdo thank you very much window.onload=function(){ $("p").click(function(){ $(this).hide(); }); }; produced no error and the code run as expected. 👍
17th Jan 2019, 8:36 PM
asa22
+ 3
Is it possible that the JS code in the JS pane was executed before the jQuery file was read from <script src ...>? I once read that SoloLearn inserts the JS pane content in the beginning of the document <head> section, it might be that's the reason, because as asa22 said, the script runs just fine if it is in the <head> section, assumed after the <script src>.
17th Jan 2019, 12:47 AM
Ipang
+ 2
asa22 Sorry for late reply. Yes, it is a possibility, but I'm not sure if it works the same between Android and iOS. I tested by opening your code in my old Android phone for editing, and put alert("jQuery loaded") below the jQuery <script src> in HTML pane, and another alert("JS pane loaded") below the code in JS pane, but from my observation, the message "jQuery loaded" comes first, followed by "JS pane loaded", so I'm still not so sure why it happened. Anyways, as a side note, your code runs just fine here in my phone, I hope you can find a solution for this soon 👍
17th Jan 2019, 8:14 AM
Ipang
+ 2
On sl the js tab content is inserted at end (eg. as last child) of head of generated html document (which is executed by web engine). At least so works on android but i dont think that on iOS is different 😕
17th Jan 2019, 8:56 AM
KrOW
KrOW - avatar
+ 2
asa22 can you execute this https://code.sololearn.com/W8W0w5xcgXi0/?ref=app and tell me what is printed on console?
17th Jan 2019, 8:59 AM
KrOW
KrOW - avatar
+ 2
KrOW Thank you very much for your efforts :) my iOS device has the latest version concole say only ReferenceError: Can't find variable: $ at Line: 3 test
17th Jan 2019, 3:35 PM
asa22
+ 2
It has to do with ios, try wrapping the whole thing in window.onload = function (){}works for me .
17th Jan 2019, 8:28 PM
xpnvdo
xpnvdo - avatar
+ 1
asa22 Just for understand: if you run the code without edit it (like its now), the error raise or not?
16th Jan 2019, 10:22 PM
KrOW
KrOW - avatar
+ 1
asa22 Strange... I have not problem with it... Have you tried to run on your device browser right? It works on it?
16th Jan 2019, 10:38 PM
KrOW
KrOW - avatar
+ 1
asa22 Can you copy/paste the complete error message?
16th Jan 2019, 10:53 PM
KrOW
KrOW - avatar
+ 1
KrOW this is the complete message „ReferenceError: Can't find variable: $ at Line: 1“, nothing more Ipang i think also this is the reason, but this behavior is new. I prefer to separate javascript or css. Code with jquery produced no error last year in the mobile device.
17th Jan 2019, 5:34 AM
asa22
0
hi r8w9, thank for your answer i am using the latest version of sololearn for ios with iPad. maybe this?
16th Jan 2019, 9:53 PM
asa22
0
yes, only in the mobile device and with separating the jquery code in the js area. therefore i made the script in the html disabled.
16th Jan 2019, 10:12 PM
asa22
0
yes, the error raise with this code. this behavior is new, last year in december i have no problem with this.
16th Jan 2019, 10:27 PM
asa22
0
KrOW I have no problem with safari and https://www.sololearn.com, only with the app.
16th Jan 2019, 10:43 PM
asa22