0
I am using the lib instascan to read qr code. but I am unable to send the result via post with ajax. anyone can help?
The code I’m using is below:
qr
<h1>qr scanner</h1>
<video id="preview"></video>
<div id="conteudo"></div>
<script type="text/javascript">
let scanner = new Instascan.Scanner({ video: document.getElementById('preview') });
scanner.addListener('scan', function lerQrcode(content) {
//alert(content);
gravar(content);
document.getElementById('conteudo').innerHTML = content;
});
function gravar(){
$.ajax({
method: "POST",
url: "dados.php",
data: '', // aqui deveria executar o post dos dados lidos
success: function(data){
alert(data.teste);
}
});
}
Instascan.Camera.getCameras().then(function (cameras) {
if (cameras.length > 0) {
scanner.start(cameras[0]);
} else {
console.error('No cameras found.');
}
}).catch(function (e) {
console.error(e);
});
// executar o post
</script>
The date is '', it should be content, right? To do this you would create a global variable to receive the content value in the scanner scanner scanner and pass in the date attribute this variable.
– Giuliana Bezerra