weixin_33739541 2015-08-11 17:11 采纳率: 0%
浏览 19

QR码信息提取

I'm currently experimenting with trying to extract the information from a QR code located on a local web server. There's an example below (Example 1), however, in that case, the file is online and on the same domain.

Example 1

My code consists of a user selecting a png QR code from their computer and pressing a submit button. The form should use Ajax and JSON to upload the file through the provided API and receive the information in an array.

Here's the code I have available:

<html>
<head>
<title>QR Code Reader</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script language="Javascript">
function fileUpload(){
    //grab form data
    var formData = new FormData($('form')[0]);
    console.log(formData);
    
        $.ajax({
            url: 'http://api.qrserver.com/v1/read-qr-code/',
            method: 'POST',
            dataType: 'jsonp',
            data: formData,
            //async: true,
            cache: false,
            contentType: false,
            //crossDomain: true,
            processData: false,
            success: function returnedResult(result){
                console.log(result);
            },
            error: alert('error')
        });
    
    
    return false;
}

$(document).ready(function() {
    
});
</script>
</head>
<body>

<form role="form" enctype="multipart/form-data" action="http://api.qrserver.com/v1/read-qr-code/" method="POST">
    <!-- MAX_FILE_SIZE (maximum file size in bytes) must precede the file input field used to upload the QR code image -->
    <input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
    <div class="form-group">
        <!-- The "name" of the input field has to be "file" as it is the name of the POST parameter -->
        <label for="file">Choose QR code image to read/scan:</label>
        <input type="file" class="form-control" id="file" placeholder="Enter email" name="file">
    </div>
    <!-- <button type="button" class="btn btn-default" onClick="fileUpload(this.form,'http://api.qrserver.com/v1/read-qr-code/','upload'); return false;">Submit</button> -->
    <button type="button" class="btn btn-default" onClick="fileUpload(); return false;">Submit</button>
</form>
  
  
<div id="upload"></div>
</body>
</html>

Here is a sample image: HelloWorld

Running this code results in a Console error (in Chrome). Any help is appreciated.

Best regards.

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度