DrS
DrS

Reputation: 342

jQueryMobile Does not load with Phonegap on Android

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: $

Upvotes: 1

Views: 1117

Answers (1)

Gajotres
Gajotres

Reputation: 57309

Downgrade your jQuery version from 2.0.2 to 1.9.1 or 1.8.3

jQuery Mobile is locked to certain jQuery versions and current jQuery Mobile 1.3.1 will work with jQuery 1.7 up to 1.9.3.

Upvotes: 1

Related Questions