1

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: $
7
  • 1
    where are you loading jquery itself? Commented Jun 6, 2013 at 15:09
  • Because .ready doesn't work with jQueryMobile. use pageinit instead. $(document).on('pageinit', function () { alert(); }); Also you have to include jQuery with jQuery Mobile. Commented Jun 6, 2013 at 15:09
  • @Omar Edited my question to reflect new issues. Commented Jun 6, 2013 at 15:21
  • 1
    What jQuery version are you using? Commented Jun 6, 2013 at 15:25
  • 1
    @Gajotres Success! If you want to post your comment as an answer, I would be happy to accept it. Commented Jun 6, 2013 at 15:56

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.