javascript - After scanning the barcode with WeChat, how do you parse the result?

WBOY
Release: 2016-08-04 09:21:31
Original
1925 people have browsed it

<code>wx.scanQRCode({
        needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
        scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
        success: function (res) {
            var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
        }
});</code>
Copy after login
Copy after login

How to parse the obtained result?

Reply content:

<code>wx.scanQRCode({
        needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
        scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
        success: function (res) {
            var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
        }
});</code>
Copy after login
Copy after login

How to parse the obtained result?

<code> var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果</code>
Copy after login

Use WeChat’s debugger and console.log() to print the result numerical analysis

What do you mean by your question?
I don’t understand. Isn't result the result of scanning?
You can use the string method to get what you want,
or ajax and pass it to the backend
or window.location.href = resultYou can achieve page jump

First of all, what type is your resdata? If it is in json format, use JSON.parse to convert it into an object and continue the operation.

<code>success: function (res) {
    var result = JSON.parse(res);  //这里把json类型的res转换成对象
    if(result.needResult == 1) {
        alert('nice!');
    }
}</code>
Copy after login
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!