PhoneGap/Cordova:很好的模拟器,突然无法在设备上工作:找不到jQuery

dgi*_*gig 1 jquery ios jquery-mobile cordova cordova-2.0.0

这突然开始发生了:我的老板在短时间的商务旅行中使用了应用程序的开发副本,并在旅行中报告了这个错误.我假设我已经对从服务器返回的json进行了一些更改并且破坏了它,但是现在我已经将它恢复了,它似乎与我在服务器上的工作完全没有关系.

这是我在控制台中收到的错误消息:

Error in success callback: Geolocation3 = ReferenceError: Can't find variable: jQuery
Run Code Online (Sandbox Code Playgroud)

要么

Error in success callback: Geolocation3 = ReferenceError: Can't find variable: $
Run Code Online (Sandbox Code Playgroud)

很明显,它只是找不到jQuery.它执行'deviceReady'就好了.但它在模拟器中工作正常.我将jQuery CDN用于jQM和jQ,并且可以通过浏览器访问它们.

什么给出了什么?为什么它突然无法找到jQuery - 而且只能在设备上找到?

我在网上看到了很多类似的问题,但没有一个有明确的答案.有些是"干净和重建"其他人是简单的错别字....但没有这个.这不是位置权限问题.这不是连接问题.这不是网址白名单问题.

一如既往地感谢您的帮助.谢谢!


我将尽可能多地提供以下代码:

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
    <title>XXXXXX</title> 
    <link rel="stylesheet" href="css/jquery.mobile.css" />
    <link rel="stylesheet" href="css/themes/app-2012-11-30.css" />
    <link rel="stylesheet" type="text/css" href="spec/lib/photoswipe/photoswipe.css" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <!-- cordova -->
    <script src="cordova-2.1.0.js" type="text/javascript"></script>
    <!-- jquery -->
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
    <!-- Google -->
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
    <!-- Add ons -->
    <script src="spec/lib/photoswipe/lib/klass.min.js"></script>
    <script src="spec/lib/photoswipe/code.photoswipe.jquery-3.0.5.js"></script>
    <!-- Objects -->
    <script src="js/map.js" type="text/javascript"></script>
    <script src="js/prefs.js" type="text/javascript"></script>
    <script src="js/search.js" type="text/javascript"></script>
    <script src="js/storage.js" type="text/javascript"></script> 
    <script src="js/helpers.js" type="text/javascript"></script>
    <script src="js/player.js" type="text/javascript"></script> 
    <script src="js/record.js" type="text/javascript"></script>  
    <script src="js/connection.js" type="text/javascript"></script> 
    <script src="js/location.js" type="text/javascript"></script>  
    <script src="js/header-footer.js" type="text/javascript"></script>
    <script src="js/featured.js" type="text/javascript"></script>
    <script src="js/list.js" type="text/javascript"></script>
    <script src="js/index.js" type="text/javascript"></script>
    <script type="text/javascript">
        document.addEventListener("deviceready", onDeviceReady, false);
        function onDeviceReady(){
            console.log('device ready');
            storageSetUp();
            checkConnection();
            getLocation();
            showFeatured();
            getSetUp();
            clUpdate();
            $(document).bind( 'mobileinit', function(){
                $.mobile.defaultPageTransition = "none";
                $.mobile.loader.prototype.options.textVisible=false;
                $.mobile.loader.prototype.options.html = '<div class="loading"></div>';
                $.mobile.pushStateEnabled = false;
            });
            $(document).bind('pagebeforeshow',function(){
                setHeaderFooterInfo();
            });         
        }
    </script>
Run Code Online (Sandbox Code Playgroud)

getLocation位于.js文件中.你在那里看到函数getStreetAddress,它包含一个ajax调用($ .ajax或jQuery.ajax),这就是它给出错误的地方.

function getLocation()
{
    gLAttempt++;
    navigator.geolocation.getCurrentPosition(onLocationSuccess, onLocationError);
} 

// onSuccess Geolocation
function onLocationSuccess(position)
{
    var lat = position.coords.latitude;
    var lng = position.coords.longitude;
    Storage.location.lat = parseFloat(lat.toFixed(6));
    Storage.location.lng = parseFloat(lng.toFixed(6));
    Storage.location.coords = lat.toFixed(6) + ',' + lng.toFixed(6);
    if(ajax_rg == null){
        getStreetAddress(Storage.location.coords);
    }
}
Run Code Online (Sandbox Code Playgroud)

Nis*_*air 5

我能想到的两种可能情景:

  1. iOS设备区分大小写,包含文件/文件夹名称.确保对所有添加的文件和文件夹使用相同的大小写.请记住,iOS模拟器不区分大小写.所以不区分大小写的文件引用将在模拟器上工作,但不能在设备中工作.

  2. 从CDN中删除jQuery引用并在本地添加它.当您打包应用程序并进行部署时,使用CDN并没有多大意义.可能会发生你的onDeviceReady事件被触发但jQuery文件没有从CDN下载...