Home >Backend Development >PHP Tutorial >javascript - After scanning the barcode with WeChat, how do you parse the result?

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

WBOY
WBOYOriginal
2016-08-04 09:21:311964browse

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

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>

How to parse the obtained result?

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

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>
Statement:
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