3

I load my index.html from my android app which is built using Cordova. I have included my jquery file correctly, but I still get the error uncaught reference error jQuery is not defined.

     <html>
        <head>
            <title id="title" name="title"></title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
            <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
            <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />        
            <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> 
            <script type="text/javascript" src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
           <script type="text/javascript" charset="utf-8" src="../abc/js/mydevice.js"></script> 
           <script type="text/javascript" charset="utf-8" src="cordova.js">/script>
           <script type="text/javascript">
                (function($) {                  
                   $(document).ready(function() {             
                       document.addEventListener("deviceready", onDeviceReady, false);                                                    
                   });
                })(jQuery);

            </script>

        </head>
    <body>
    </body>
    </html>

I get the error Uncaught Reference error jQuery is not defined from document ready function. I get the same error from mydevice.js file.

mydevice.js file looks like below

jQuery(document).ready(function(){
  /// body of the function here.....
});

My java code to launch index.html looks like below

public class AppActivity extends CordovaActivity
{
    public static final String INDEX_FILE_PATH = "file:///android_asset/www/index.html";

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // super.loadUrlTimeoutValue = 1000 * 60;
        super.init();
        // super.loadUrl(INDEX_FILE_PATH);
        loadUrl(launchUrl);              
    }
}

I have gone through this link uncaught reference error. Not sure what I am missing?

I found out, I get this error when I am using a proxy on my WIFI in android simulator. If I don't use that proxy, I don't get this error.

Community
  • 1
  • 1
yogsma
  • 9,106
  • 25
  • 86
  • 142
  • If you use external sources, then you should whitelisten them. And you should listen to the cordova-ready-event. – Joerg Mar 15 '16 at 20:25
  • Can you elaborate on whitelist them? Also as shown in code about I use document.addEventListener, that should do cordova-ready-event thing, but it doesn't even come there before I get the error about uncaught reference – yogsma Mar 15 '16 at 20:31
  • 1
    Sorry, I didn't saw the deviceready, I was fixed to the whitelisten things. Here is a link: http://cordova.apache.org/docs/en/dev/guide/appdev/whitelist/index.html Btw, why are you using external sources? It causes traffic and it makes your app slower during startup. – Joerg Mar 15 '16 at 20:42
  • External resources contain javascript bridge to java code. – yogsma Mar 16 '16 at 15:32

1 Answers1

0

If I remove the proxy I had added, this works fine without any error. Looks like a cross-domain issue.

yogsma
  • 9,106
  • 25
  • 86
  • 142