I'm using the instascan lib to read qr code. but I am not able to send the result via post with ajax. Can someone help?
The code I'm using is below:
qr sacanner
<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>