Regular javascript works, however when I try to use jQuery or jQueryMobile, it does not load. I have downloaded the compressed jQueryMobile file, and placed it in my project.
These are my script declarations in my HTML file
<script type = "text/javascript" src = "cordova-2.7.0.js"></script>
<script type = "text/javascript" src = "js/jquerymobile.js"></script>
<script type = "text/javascript" src = "js/myscript.js"></script>
This is the function in myscript.js that is not firing:
$(document).ready(function()
{
alert('at least this works');
});
I can see in logcat this error message:
06-06 14:57:19.555: D/CordovaLog(249): file:///android_asset/www/js/myscript.js: Line 15 : ReferenceError: Can't find variable: $
Which prompts me to believe that jQueryMobile isn't loading at all. The other solutions that I found regarding this error message did not work for me. Any help will be appreciated.
EDIT:
I added jQuery and swapped out deviceready for pageinit. I am still getting errors.
My new script declarations are:
<script type = "text/javascript" src = "cordova-2.7.0.js"></script>
<script type = "text/javascript" src = "js/jquery.js"></script>
<script type = "text/javascript" src = "js/jquerymobile.js"></script>
<script type = "text/javascript" src = "js/myscript.js"></script>
My new function that is not being called is:
$(document).on('pageinit', function ()
{
alert('at least this works');
});
And Here are some interesting error messages from logcat:
06-06 15:16:39.777: D/CordovaLog(219): file:///android_asset/www/js/jquery.js: Line 3345 : TypeError: Result of expression 'Object.defineProperty' [undefined] is not a function.
06-06 15:16:40.747: D/CordovaLog(219): file:///android_asset/www/js/jquerymobile.js: Line 26 : TypeError: Result of expression '$' [undefined] is not an object.
06-06 15:16:40.757: D/CordovaLog(219): file:///android_asset/www/js/myscript.js: Line 15 : ReferenceError: Can't find variable: $
.readydoesn't work with jQueryMobile. usepageinitinstead.$(document).on('pageinit', function () { alert(); });Also you have to include jQuery with jQuery Mobile.