Javascript 扫描条形码后,页面会自动刷新,但不应

Javascript 扫描条形码后,页面会自动刷新,但不应,javascript,php,html,Javascript,Php,Html,所以我在做这个项目,我使用一个条形码扫描仪,它的操作系统是WindowsCE5.0。每当我扫描条形码时,页面都会自动刷新,这是不应该的。扫描条形码后,用户应能够输入数量编号,然后用户将单击预览按钮,将用户带到另一页。我在网上搜索了这个问题的解决方案,但仍然不起作用。请帮忙。多谢各位 <?php include("webconfig.php"); ob_start(); session_start(); if(!isset($_SESSION["USER_C

所以我在做这个项目,我使用一个条形码扫描仪,它的操作系统是WindowsCE5.0。每当我扫描条形码时,页面都会自动刷新,这是不应该的。扫描条形码后,用户应能够输入数量编号,然后用户将单击预览按钮,将用户带到另一页。我在网上搜索了这个问题的解决方案,但仍然不起作用。请帮忙。多谢各位

<?php
    include("webconfig.php");
    ob_start();
    session_start();

    if(!isset($_SESSION["USER_CODE"]) || $_SESSION["ACTIVE"] == '0')
        header("location:login.php");

    $barcode = $_REQUEST["barcode"];
    $item_desc = $_REQUEST["item_desc"];
    $price = $_REQUEST["price"];
    $quantity = $_REQUEST["txtQty"];

    $pricef = number_format($price, 2); 

    $sql = ibase_query($conn, "SELECT * FROM ITEM_MASTER WHERE ITEM_CODE = '$barcode'") or die(ibase_errmsg());
    $row = ibase_fetch_assoc($sql);
    $imgname = $row['IMGNAME']; 
?>

<!DOCTYPE html>
<html>
<head>
    <link href="docs/css/metro.css" rel="stylesheet">
    <link href="docs/css/metro-icons.css" rel="stylesheet">
    <link href="docs/css/docs.css" rel="stylesheet">

    <script src="docs/js/jquery-2.1.3.min.js"></script>
    <script src="docs/js/metro.js"></script>
    <script src="docs/js/docs.js"></script>
    <script src="docs/js/prettify/run_prettify.js"></script>
    <script src="docs/js/ga.js"></script>
    <script src="js/jquery.js"></script>
    <script src="js/jquery.ajaxcomplete.js"></script>

    <script type="text/javascript" src="keyboard.js" charset="UTF-8"></script>
    <link rel="stylesheet" type="text/css" href="keyboard.css">
    <link rel="shortcut icon" href="_img/assigns-favicon.PNG">

    <title>Albert Smith Signs - Warehouse Inventory System</title>  
</head>
<body>
    <div class="page-content">
        <div class="align-center">
            <div class="container">
                <!-- Default -->
                <div class="panel">
                    <div class="content">
                        <div class="grid">
                            <div class="row cells12">
                                <!-- Default -->
                                <div class="panel">
                                    <div class="heading">
                                        <span class="title">ENTER QUANTITY</span>
                                    </div>
                                    <div class="content">
                                        <div class="grid">
                                            <div class="row cells12">
                                                <div class="cell colspan12">

                                                    <form onsubmit="return false;" method="post">
                                                        <label>Enter Quantity</label>
                                                        <br />
                                                        <div class="input-control text full-size" placeholder="Type search keyword here" data-role="input">
                                                            <!-- <input name="txtQty" class="keyboardInput" style="width: 225px;" type="text" value="1" autocomplete="off" /> -->
                                                            Scan Barcode
                                                            <input name="txtBarcode" id="ip" type="text" autofocus />
                                                            <br />
                                                            <br />
                                                            Enter Quantity
                                                            <input name="txtQty" id="next" type="text" />
                                                        </div>
                                                        <div class="cell colspan12">
                                                        <hr>
                                                        <br />
                                                        <br />
                                                        <br />
                                                        <br />
                                                        <br />

                                                        <input type="submit" onsubmit="return true;" name="btnPreview" style="width:80px; height:50px;" class="button primary rounded large-button" value="Preview" />
                                                        </div>

                                                </div>

                                                <?php
                                                    if(isset($_POST['btnPreview']) && $_POST['txtQty'] > 0)
                                                    {
                                                        $quantity = $_POST['txtQty'];
                                                        $barcode = $_POST['txtBarcode'];

                                                        $sql = "SELECT * FROM ITEM_MASTER WHERE ITEM_CODE = '$barcode'";
                                                        $query = ibase_query($conn, $sql) or die(ibase_errmsg());

                                                        if ($row = ibase_fetch_assoc($query))
                                                        {
                                                            $item_desc = $row['ITEM_DESC'];
                                                            $price = $row['COST'];
                                                            header("location:preview.php?barcode=$barcode&quantity=$quantity&item_desc=$item_desc&price=$price");
                                                        }
                                                        else{
                                                            echo "Barcode not found";
                                                        }
                                                    }
                                                ?>
                                                </form>
                                                <div class="cell colspan1">
                                                    &nbsp;
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div><!-- panel -->
                            </div><!-- row cells12 -->
                        </div><!-- grid -->
                    </div><!-- content -->
                </div><!-- panel -->
            </div>
        </div>
    </div>

    <script>
        //$("#ip").focus();
        /*var d = false;

        $("#ip").on('change', function(){
        //$("#ip").keyup(function(){
            if(d == false){
                $(".block").animate({"top": "-=50px"});
                d = true;
            }

            var v = $(this).val();
            $(".res").html("Search results for " + v );

            $("#next").focus();
        });*/

        $("#ip").focus();

        function init() {
            key_count_global = 0; // Global variable
            document.getElementById("ip").onkeypress = function() {
                key_count_global++;
                setTimeout("lookup("+key_count_global+")", 1000);//Function will be called 1 second after user types anything. Feel free to change this value.
            }
        }
        window.onload = init; //or $(document).ready(init); - for jQuery

        function lookup(key_count) {
            if(key_count == key_count_global) { // The control will reach this point 1 second after user stops typing.
                // Do the ajax lookup here.
                $("#next").focus();
            }
        }
    </script>

</body>
</html>

可能是扫描器问题,通常扫描器扫描后会执行一项操作,我猜在这种情况下,他们正在扫描并进入。。。在提交表单时输入结果,请阅读扫描仪手册。。这很可能是你的问题。。谢谢@Naruto。我会检查的。可能是扫描仪的问题,通常扫描仪扫描后会做一个动作,我猜在这种情况下,他们会扫描并进入。。。在提交表单时输入结果,请阅读扫描仪手册。。这很可能是你的问题。。谢谢@Naruto。我去查一下。