Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 关于扫条码的问题

关于扫条码的问题

Jun 23, 2016 pm 01:26 PM

hp表
id         name(货品名称)       kucun(库存)       danwei(单位)         danjia(出库单价)           tiaoma(条码)
1           .................................................................................................................                 1234



     
           
     
     
           
     
扫条码:

                        
                         
                        
                        
                        
                        
                        
                        
                        
                        
                         请问在文本tiaoma中扫入1234后,怎么自动将hp表中id为1的相关信息显示在这里???
                      
关于扫条码的问题 货品名称 库存 数量 单位 单价 合计

           


回复讨论(解决方案)

并且每次扫完读取到货品后,自动将文本tiaoma清空(以便扫另一个物品),并且光标显示在文本tiaoma里

你需要用到ajax

你需要用到ajax



请帮忙写一下

有人帮忙写下吗?

是扫了条形码后跳转到这个页面吗?
select * from hp where tiaoma='1234';

找到记录后echo出来。

是扫了条形码后跳转到这个页面吗?
select * from hp where tiaoma='1234';

找到记录后echo出来。



我的意思是,每扫一个就在下面显示一个,扫几个就显示几个

扫完,提交到php,然后返回内容,用js加一个table就可以了。
ajax操作。

问题是你扫的程序是怎样的。

扫完,提交到php,然后返回内容,用js加一个table就可以了。
ajax操作。

问题是你扫的程序是怎样的。


不会AJAX,你能帮忙写一下吗?
扫的程序就是一个表单提交,在文本框里扫了条码后,文本框里就会出现一串数字,然后再提交

在网上搜到一个类拟的:

    


         
        <script></script>
        <script> <br /> $(document).ready(function (){ <br /> //$("#name").focus(); input框输入内容然后刷新页面,input框内容还在(firefox) <br /> clearText(); // 改用clearText <br /> $("#addBtn").click(function (){ <br /> $("#table1").append(getNewRow()); <br /> clearText(); <br /> }); <br /> $("#table1").on('click', ".delBtn", function (){ <br /> $(this).parent().parent().remove(); <br /> }); <br /> }); <br /> function clearText(){ <br /> $("#name").val(""); <br /> $("#name").focus(); <br /> } <br /> function getNewRow(){ <br /> var btn = $("<input class='delBtn' type='button' value='删除' />"); <br /> var newRow = $("<tr>").append($("<td>").append( $("#name").val())) <br /> //1、怎么在这里提交到PHP? <br /> //2、怎么让红色$("#name").val()这个显示为PHP返回来的数据库的值? <br /> .append($("<td>").append(btn)); <br /> return newRow; <br /> } <br /> </script>

    
    
        
            
                
                
            
        
名称:

        
            
                
                
            
        
名称 操作

    

3、怎么在这个里输入条码后直接添加一行,而不需要点击??

http://www.cnblogs.com/Johnny_Z/archive/2012/06/17/2552597.html

为什么下面的代码不行呢?错在哪呢?
<script> <br /> $(document).ready(function (){ <br /> //$("#name").focus(); input框输入内容然后刷新页面,input框内容还在(firefox) <br /> clearText(); // 改用clearText <br /> $("#addBtn").click(function (){ <br /> $("#table1").append(getNewRow()); <br /> clearText(); <br /> }); <br /> $("#table1").on('click', ".delBtn", function (){ <br /> $(this).parent().parent().remove(); <br /> }); <br /> }); <br /> function clearText(){ <br /> $("#name").val(""); <br /> $("#name").focus(); <br /> } <br /> <br /> function getNewRow(){ <br /> $.get("/oa/oa_api.php?act=get_oa_vip",{ //为什么这里没有用 <br /> vip:$("#name").val(), <br /> async:false, <br /> rand: Math.random() <br /> },function(data){ <br /> if(data.status.code=="1") <br /> { <br /> //成功 <br /> var jifen = data.record.jifen; <br /> var xy_id = data.record.xy_id; <br /> var btn = $("<input class='delBtn' type='button' value='删除' />"); <br /> var newRow = $("<tr>").append($("<td>").append(xy_id)) <br /> .append($("<td>").append(jifen)) <br /> .append($("<td>").append(btn)); <br /> return newRow; <br /> } <br /> else <br /> { <br /> alert('读取数据错误!'); <br /> } <br /> },"json"); <br /> } <br /> </script>


            
                
                
            
        
名称:

        
            
                
                
            
        
名称 操作


oa_api.php如下:
if($action == 'get_oa_vip')
{
if ( !(isset($_SESSION['userid']) && $_SESSION['userid'] > 0) )
{
ajax_error('请先登录!');
exit;
}

//取school_id 如果没有school_id则退出
$sql = "select schoolID from " . $fdyu->table('users') . " where user_id=" . $_SESSION['userid'];
$school_id = $db->getOne($sql);
if($school_id  {
ajax_error('您不属于任何学校,无法使用该功能!');
exit;
}

$vip = $_GET['vip'];

$ajax = array();

$sql = "select xy_id,jifen from " . $fdyu->table('oa_vip') . " where vip='" . $vip . "' and school_id=" . $school_id . "";
$res = $db->query($sql);
if($res)
{
$ajax['status']['code'] = '1'; //成功
$ajax['record']['jifen'] = $row['jifen'];
$ajax['record']['xy_id'] = $row['xy_id'];
}

echo json_encode($ajax);
exit;
}

经过一层层排查,PHP返回的值也获取到了,现在就是不知道怎么把获取到的值放到


             
                 
                 
             
         
名称 操作

这个里去,也就是下面这一段有问题,请问应该怎么写?
var newRow = $("").append($("").append(xy_id))
.append($(" ").append(jifen))
 .append($(" ").append(btn));
return newRow;

$,post(url,{args:args},function(data){
    alert(data);
})

通过异步获取结果集

$.ajax({  
       type: "POST", //用POST方式传输         
       url: 'f.php', //目标地址.  
         dataType: "json", //数据格式:JSON  
       //data: "dealType=" + dealType +"&uid=" + uid + "&code=" + code,  
         data: "&a="+mobile,  
       success: function(json){   
            if(json.msgid==1){//成功的处理  
                alert(json.html);  
            }  
            else if(json.msgid==2){//失败的处理  
                alert(json.html);  
            }  
            else{  
                alert(json.html);  
            }  
         }  
     });  

成功后,用jquery事件,加入

var newRow = $("

").append($("").append(xy_id))
.append($(" ").append(jifen))
 .append($(" ").append(btn));
return newRow;


试下

现在我的程序已经能正常获取到返回的值,
if(data.status.code=="1")
{
//成功
var jifen = data.record.jifen;
var xy_id = data.record.xy_id;//这里能正常获取到了
....

现在我的问题就是,怎么将获取到的值插入到下面的table里


             
                 
                
                 
             
名称 积分 操作

谁能告诉我怎么写?

现在我的程序已经能正常获取到返回的值,
if(data.status.code=="1")
{
//成功
var jifen = data.record.jifen;
var xy_id = data.record.xy_id;//这里能正常获取到了
....

现在我的问题就是,怎么将获取到的值插入到下面的table里


             
                 
                
                 
             
名称 积分 操作

只需要回答我这个问题就行了,不要写新的方法了

都一个月了,还没解决?
网上动态添加表行的 js 代码多了去了,一个月都找不到适合你的?

不知道搜什么关键字,所以一直等答案
现在就差最后一步了,拜托帮我写一下,我现在去网上搜肯定与我现在写的不一样,我又得研究老久了

有人帮忙写一下不?

<table id="table1" border="1"> <tr>  <td>名称</td>  <td>积分</td>  <td>操作</td> </tr></table><script>var t = document.getElementById('table1');var tr = t.insertRow();var td1 = tr.insertCell();td1.innerHTML = 1;var td2 = tr.insertCell();td2.innerHTML = 2;var td3 = tr.insertCell();td3.innerHTML = 3;</script>
Copy after login

能看明白吗?

可以了,谢谢
但还有一个问题麻烦一下你,就是同一条码不能重复添加应该怎么弄?

弄好了
换了种写法:
function getNewRow(){
$.get("/oa/oa_api.php?act=get_oa_vip",{
vip:$("#name").val(),
async:false,
rand: Math.random()
},function(data){
if(data.status.code=="1")
{
//成功
var jifen = data.record.jifen;
var xy_id = data.record.xy_id;
if( $("#tr_"+xy_id).length > 0 )
{
clearText();
return false;
}
var btn = '';
var trHtml;
trHtml = '

';
trHtml += '' + xy_id + '';
trHtml += '' + jifen + '';
trHtml += '' + btn + ' ';
$("#table1").append(trHtml);
clearText();
}
},"json");
            }
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

How do you prevent SQL Injection in PHP? (Prepared statements, PDO) How do you prevent SQL Injection in PHP? (Prepared statements, PDO) Apr 15, 2025 am 12:15 AM

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles