title: Trying to scan a QR Code then call an API
body: <p>I am trying to create a mobile app where the user will scan a unique QR code, the program should then perform a check to make sure that the correct QR code was scanned (instead of just a random QR code) and if the correct code QR was scanned the API should be called. I found a javascript qr scanner that works on mobile phones from <a href="https://www.sitepoint.com/create-qr-code-reader-mobile-website/" rel="nofollow noreferrer">https://www.sitepoint.com/create-qr-code-reader-mobile-website/</a>. This all works perfectly in that it accesses the devices camera and scans a QR code but I am struggling on how to perform a check that the correct QR code was scanned. For the sake of testing the "correct" QR code just translates to a string "hello".</p>
  
  <p>I have tried using alert(res) to find the point where the QR is decoded. When I try to use an if statement to compare the decoded QR to a variable equivalent to "hello", the QR scanner just stops working.</p>
  
  <p>The full code can be seen at <a href="https://www.sitepoint.com/create-qr-code-reader-mobile-website/" rel="nofollow noreferrer">https://www.sitepoint.com/create-qr-code-reader-mobile-website/</a></p>
  
  <p>Here is the part which decodes the QR image. </p>
  
  <pre><code>function openQRCamera(node) {
    var reader = new FileReader();
    reader.onload = function() {
      node.value = "";
      qrcode.callback = function(res) {
        if(res instanceof Error) {
          alert("No QR code found. Please make sure the QR code is within the camera's frame and try again.");
        } else {
          node.parentNode.previousElementSibling.value = res;      }
          alert(res)
      };
      qrcode.decode(reader.result);
    };
    reader.readAsDataURL(node.files[0]);
  }
  </code></pre>
  
  <p>The part where it says alert(res) is where i beleive the QR image is decoded, I have tried various if statments but can not get it to work can anyone help.</p>