0

I'm trying to write a simple web app that will read from a 1D barcode and insert the value to a MySQL database.

Ideally this website will access to a camera and just scan the barcodes, that are shown to it. There will be no further user interaction.

I have achieved scanning the barcodes and extracting the information in Javascript using ZXing. Now my research has shown me that you can't just insert a php inside javascript. So I must stop the infinite loop of the function and pass data to php, where it can be inserted to MySQL. However after I return from the function and update the database, I need to refresh the webpage to scan a new barcode.

The problem is here I don't want to refresh the webpage because the browser, that runs the webpage won't have any mouse/keyboard(user interaction). How can I call a javascript function infinite times without refreshing my browser?

Cristik
  • 30,989
  • 25
  • 91
  • 127
Kaan
  • 33
  • 3

2 Answers2

0

After scaning, send data to php by ajax (try some javascript framework like jQuery or others...)

By javascript, you can refresh page in oncomplete state of ajax request without any keybord or mouse action.

Martin Hrabal
  • 102
  • 1
  • 2
  • 10
0

I think your best chance is to take a look to javascript Ajax calls.

In client side - The infinite loop call to a function that handles de ajax call. That ajax call should sent a GET o POST to a php page. - You don't need to refresh the page. If you need to return some data, do it in the ajax response function.

In the server side The .php handle the insertion of data to MySQL.

Recomendation: Use jQuery, a javascript library: https://jquery.com/

Take a look: Using Jquery Ajax to retrieve data from Mysql

Community
  • 1
  • 1
RubenS
  • 1
  • 2