简体   繁体   English

在使用JQueryMobile和IBM Worklight 6.0时找不到$

[英]can't find $ - while using JQueryMobile and IBM Worklight 6.0

I am trying to integrate a bar code scanner onto a phone gap app developed on worklight, the current html page comes from a href from the main page like this. 我正在尝试将条形码扫描仪集成到在工作灯上开发的手机间隙应用程序中,当前的html页面来自主页面的href,就像这样。

<a data-role="button" href="itemscan.html" rel="external" data-shadow="false"
    data-theme="none"><img src="images/dashboard_barcode.png"  ></a>

My html Page: 我的HTML页面:

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
<head>
<title>BarCode Scanner</title>
            <link rel="stylesheet" href="jqueryMobile/jquery/jquery.mobile-1.3.2.css">
            <script src="jqueryMobile/jquery/jquery.mobile-1.3.2.js"></script>


</head>
    <body>
        <div class="app">
            <h1>Zxing Scanner!!</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
                <p id="barcoderesult">Bar Code Result: Nil</p>

            </div>
        </div>
        <script type="text/javascript" src="js/cordova-2.5.0.js"></script>
        <script type="text/javascript" src="modules/core/CoreFunc.js"></script>
        <script type="text/javascript" src="js/barcodescanner.js"></script>
        <script type="text/javascript" src="js/itemscan.js"></script>
        <script type="text/javascript" src="js/MenuPanel.js"></script>
        <script type="text/javascript">
            app.initialize();
       </script>
    </body>
</html>

JS file: JS档案:

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicity call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
        // demo the scan
        console.log('about to scan');
        try {
            var scanned = app.scan();
            console.log('scan triggered', scanned);
        } catch (e) {
            console.log('scan failed');
            console.log(JSON.stringify(e));
            console.log('that sucks... reloading in 10');
            setTimeout(function() {
                console.log('reloading now...');
                app.onDeviceReady();
            }, 10000);
        }
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    },
    /**
     * here is an example for scanning a barcode...
     * obviously, your own JS logic <<here>>
     *
     * Note the require() method is called on window.cordova
     *   this is different than the readme!
     */
    scan: function() {

        console.log('scan(): init');
        // documentation said the syntax was this:
        // var scanner = window.PhoneGap.require("cordova/plugin/BarcodeScanner");
        // but playing with options, seems like it should be this:
        var scanner = window.cordova.require("cordova/plugin/BarcodeScanner");
        scanner.scan(
                function (result) {

                    var parentElement = document.getElementById("barcoderesult");
                    parentElement.innerHTML = result.text;
//                    alert("We got a barcode\n" +
//                        "Result: " + result.text + "\n" +
//                        "Format: " + result.format + "\n" +
//                        "Cancelled: " + result.cancelled);
                    console.log("We got a barcode\n" +
                            "Result: " + result.text + "\n" +
                            "Format: " + result.format + "\n" +
                            "Cancelled: " + result.cancelled);
                  $.mobile.changePage( "../itemDetails.html", { transition: "slideup", changeHash: false });

                },
                function (error) {
                    alert("Scanning failed: " + error);
                }
                );
    }
};

The scanning works fine, after a success callback I get the bar code and then I get this, I am not able to do changePage. 扫描工作正常,成功回调后,我得到条形码,然后我得到这个,我无法做changePage。

[LOG] Error in error callback: BarcodeScanner957715450 = ReferenceError: Can't find variable: $ [LOG]错误回调错误:BarcodeScanner957715450 = ReferenceError:找不到变量:$

From all the searching I have done, I have found that the jQuery is not loaded properly. 从我所做的所有搜索中,我发现jQuery没有正确加载。 I am kinda new to all these web technologies so any help is appreciated. 我是所有这些网络技术的新手,所以任何帮助表示赞赏。

Can't find variable: $ jquery not loaded into your code. Can't find variable: $ jquery没有加载到你的代码中。 please make sure jquery loaded properly and there is no jquery conflict as stated Gamex. 请确保正确加载jquery并且没有如Gamex所述的jquery冲突。

window.onload = function() {
    if (window.jQuery) {        
    alert("jQuery is loaded  !");
    } else {        
    alert("jQuery is not loaded");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IBM Worklight 6.0-在Visual Studio中启动Windows 8 App设置了错误的WL服务器IP地址 - IBM Worklight 6.0 - Launch Windows 8 App in Visual Studio sets a wrong WL Server IP Address IBM Worklight-单击按钮导航到另一个HTML页面不起作用(多页面应用程序) - IBM Worklight - Clicking a button to navigate to another HTML page doesn't work (multiple page application) jQueryMobile无法向下滚动到动态创建的页面内容 - jQueryMobile Can't scroll down to dynamically created page content 无法在IBM Worklight上集成Google地图 - Unable to integrate Google Maps on IBM Worklight 使用 Mat-Table-Exporter 时找不到属性“exporter” - Can't find property 'exporter' while using Mat-Table-Exporter JQueryMobile按钮不起作用 - JQueryMobile button isn't working 一边拼凑请求和美味的汤,一边找不到班级的跨度 - Can't find span by class while scraping with requests and beautiful soup 使用HTMLAgilityPack找不到节点 - Can't find node using HTMLAgilityPack 使用硒无法通过ID查找元素 - Can't find element by id using selenium 使用.indexOf()找不到数组索引 - Can't find the array index using .indexOf()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM