JQM,Phonegap,一个服务器功能崩溃我的应用程序

时间:2014-11-14 15:38:52

标签: javascript jquery ajax jquery-mobile cordova

我正在开发混合应用程序(JQM 1.4 + Phonegap 3.6.3)。

我有一个函数populateImagesUrlsLocalAndServer来检查我的服务器上是否存在图像文件,但我无法使用此功能,因为它会使我的应用程序在Phonegap上崩溃... 我找不到原因。 你能帮我解决一下这个问题吗?我可以再次在我的应用程序中使用这个功能吗?

感谢

function populateImagesUrlsLocalAndServer(str, baseUrl, type) {
    if (connectionStatus == "online") { 
        if (UrlExists('./'+baseUrl+str)) { //local file
            imagesUrls[str] = './'+baseUrl+str;
        } else if (isPhoneGap && UrlExists('http://boardlineapp.com/app/'+baseUrl+str)) { //server file....we exclude this for desktop browser because of cross domain error
            console.log('retrieving '+'http://boardlineapp.com/app/'+baseUrl+str+' on server')
            imagesUrls[str] = 'http://boardlineapp.com/app/'+baseUrl+str;
        } else {
            imagesUrls[str] = './'+baseUrl+'default.png';
        }
    } else { //offline
        if (UrlExists('./'+baseUrl+str)) { //local file
            imagesUrls[str] = './'+baseUrl+str;
        } else {
            imagesUrls[str] = './'+baseUrl+'default.png';
        }
    }
    imagesUrls[str+'type'] = type;
}

相反,现在我正在使用:

function populateImagesUrls(str, baseUrl, type) {
    if (    str == 'byrne-ow-fender.png'
         || str == 'ci-tacogrinder.png'
         || str == 'noamizuno.png'
         || str == 'brendanmargieson.png'
         || str == 'kaihing.png'
         || str == 'dustinhollick.png'
         || str == 'dhd-thetwin.png'
        ) {
        //console.log(str);
        //console.log(baseUrl);
        imagesUrls[str] = './'+baseUrl+'default.png';
    } else {
        imagesUrls[str] = './'+baseUrl+str;
    }
    imagesUrls[str+'type'] = type;
}

调用它的函数如下:

function checkIfImagesExistAllAtOnce() {
    var prodataTemp = [];
    prodataTemp = prodata.slice();  
    prodataTemp.shift();
    prodataTemp.sort(sort_by('brand', 'name', 'model'));
    var strBrandDone;
    var strNameDone;
    var strModelDone;
    for (i = 1; i < prodataTemp.length; ++i) {

        //check brand
        var str = prodataTemp[i]['brand'].replace(/\s+/g, '').toLowerCase();
        str = str+'.png';
        if (str != strBrandDone) {
            var baseUrl = "images/brands/";
            strBrandDone = str;
            var type = "brand";
            populateImagesUrls(str, baseUrl, type);
            //populateImagesUrlsLocalAndServer(str, baseUrl, type);
        }

        //check pro image
        var str = prodataTemp[i]['name'].replace(/\s+/g, '').toLowerCase();
        str = str+'.png';
        if (str != strNameDone) {
            var baseUrl = "images/pros/";
            strNameDone = str;
            var type = "pro";
            populateImagesUrls(str, baseUrl, type);
            //populateImagesUrlsLocalAndServer(str, baseUrl, type);
        }

        //check board image
        var str = prodataTemp[i]['imageName'];
        if (str != strModelDone) {
            var baseUrl = "images/boards/";
            strModelDone = str;
            var type = "board";
            populateImagesUrls(str, baseUrl, type);
            //populateImagesUrlsLocalAndServer(str, baseUrl, type);
        }

    }
    prodataTemp = null;

}

0 个答案:

没有答案