mebjas / html5-qrcode

A cross platform HTML5 QR code reader. See end to end implementation at: https://scanapp.org
https://qrcode.minhazav.dev
Apache License 2.0
4.9k stars 959 forks source link

[Feature Request] Insert into mysql DB after Scan with Ajax? #152

Closed anonuserch closed 3 years ago

anonuserch commented 3 years ago

Hello everyone, has someone already extended the code to save the QR code content in a Mysql database after each scan (with Ajax -> PHP)?

bernardarhia commented 3 years ago

Yh I have. I'm working on a project which scans the qrcode and do some ajax calls but I want to auto restart instead of always pressing the request camera permission.

mebjas commented 3 years ago

Hello everyone, has someone already extended the code to save the QR code content in a Mysql database after each scan (with Ajax -> PHP)?

yes on the onSuccessCallback you can trigger any kind of logic. Example

function saveQrContentToDb(qrMessage) {
  // .. write ajax logic here
} 

function onScanSuccess(qrMessage) {
    saveQrContentToDb(qrMessage);
}

function onScanFailure(error) {
    // skip failure conditions
}

let html5QrcodeScanner = new Html5QrcodeScanner(
    "reader", { fps: 10, qrbox: 250 }, /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);
mebjas commented 3 years ago

(please reopen if this is not clear enough)

chammeow commented 2 years ago

Hello @mebjas

Hello everyone, has someone already extended the code to save the QR code content in a Mysql database after each scan (with Ajax -> PHP)?

yes on the onSuccessCallback you can trigger any kind of logic. Example

function saveQrContentToDb(qrMessage) {
  // .. write ajax logic here
} 

function onScanSuccess(qrMessage) {
    saveQrContentToDb(qrMessage);
}

function onScanFailure(error) {
    // skip failure conditions
}

let html5QrcodeScanner = new Html5QrcodeScanner(
    "reader", { fps: 10, qrbox: 250 }, /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);

@mebjas tried this one but it doesn't seem to push thru on my ajax. here's my code. On method "updateWaybillStatus" it alerts the qrMessage and after that nothing happens no logs on my console that it performs the ajax. Please help. Thank you.

function onScanSuccess(decodedText, decodedResult) {
    updateWaybillStatus(decodedText)
    html5QrcodeScanner.clear();// ^ this will stop the scanner (video feed) and clear the scan area.
  }

//Inserts on database
  function updateWaybillStatus(qrMessage) {
    alert(qrMessage)
    $.post("{{ url('/scanParcelUpdate/') }}" + "/" + qrMessage, function(data, status) {
      console.log('success')
    });
  } 

  var html5QrcodeScanner = new Html5QrcodeScanner(
    "reader", { fps: 10, qrbox: 250 }
  );

  function onScanError(errorMessage) {
    // handle on error condition, with error message
}

  html5QrcodeScanner.render(onScanSuccess, onScanError);
maietta commented 2 years ago

This thread is very much outside the scope of this project.