OK, I've read the wiki on Scanning from a web page:Say I have a form on my page that has several inputs. One of these has a button next to it labeled "Scan."I want to push the scan button, trigger the barcode scanner app, and have the {CODE} value inserted into the associated form field. I suspect that this is an AJAX-like maneuver, and I don't claim to be an expert on such things, but I'm a fairly quick study.I've built some test code that seems to get close, but I feel like I'm missing something. Has anyone done something similar?In case anyone's curious, here's some snippets of what I've built so far. I'm willing to share the final solution if there is one.From index.php
<html>
<form>
<input id="code" type="text" value="<?php if($_SESSION['scan_code']) print $_SESSION['scan_code']?>">
<button class="btn" id="scan1">Scan1</button>
...
</form>
<script type="text/javascript">$('document').ready(function() {$('#scan1').click(function() {event.preventDefault();
// trigger the scannerwindow.open('http://<?php print $_SERVER["SERVER_NAME"]?>/~donf/vstest/scan.php?s=<?php print $session?>&c=%7BCODE%7D');session = getCookie("PHPSESSID");
// same url, but no c={CODE}. Invoke Ajax request to get the value.url = "scan.php?s=".concat(session);$.get(url, function(result) {$('#code').val(result);});});</script>
... and from scan.php
<?php
session_start();
$mysession = session_id();
if($_REQUEST["s"] != $mysession ) {
echo "failed: " . $_REQUEST["s"];
exit;
} else {
if($_REQUEST["c"]) {
$_SESSION["scanned_code"] = $_REQUEST["c"];
} else {
echo $_SESSION["scanned_code"];
exit;
}
?>
<html>
<body onload="window.close();"></body>
</html>
Hi guys, how 'bout this? It works in Dolphin.
var w;
function getScan(){
w=window.open("zxing://scan/?ret="+escape("http://yourdomain/barcode.php?ret={CODE}"));
w.onload=getScanResult;
}
function getScanResult(){
var barcode=w.document.body.innerHTML;
//Windows Apache PHP adds a CR on the end, so we have to get rid of it
barcode=barcode.substr(0,barcode.length-1);
w.close();
//Now the variable "barcode" has the scan results, and you can put them anywhere you like.
}
The flow is...A page invokes the barcode scanner -- using a hyperlink or JS or whateverAn entirely separate app comes to the front and scansThe app opens URL http://yourdomain/barcode.php?ret=23423464622 -- presumably in a new windowAt that point, barcode.php can get '23423464622' from the URL.It looks like you mean that the server side read the param, render the value back in the body of a response, then parse that body in Javascript -- I think that works but isn't that the long way around?Your second example looks, at first glance, more like what I'd imagine.But it's still not updating the original page in place, right? I think that was the requirement.
On Thursday, June 21, 2012 4:52:14 PM UTC+1, alfadog wrote:
Which browser are you using? I'm trying to replicate what you have, but every time that I scan a barcode, both Dolphin Browser and Chrome are reloading the page, rather than simply jumping to the hash tag.Thanks,Scott Milliken
That's strange, perhaps a mismatch in either settings or android version. I have 2.3.4, and the code works to specification on the stock browser and on Dolphin HD....
This seems to be a version/os based problem. I had an older version Android tablet and your code worked flawlessly! I upgraded to a new tablet and phone (4.1.1 and 4.1.2) and now it opens in a new tab. Very frustrating!
<?php
if(isset($_POST['submit'])){
if(preg_match("/^\d+$/", $_POST['asset'])){
$asset=$_POST['asset'];
//Connect to sql server..
$db=mysql_connect ("") or die ('I cant connect to the db :( - ' . mysql_error());
//Select db
$mydb=mysql_select_db("booking_inout");
//Query table
$sql="SELECT `Asset No`, `Serial No`, `New Location` FROM `StockRoom` WHERE `Asset No`=" . $asset;
//Run the query
$result=mysql_query($sql);
//Create loop and loop through result
while($row=mysql_fetch_array($result)){
$AssetNo=$row['Asset No'];
$SN=$row['Serial No'];
$NewLocation=$row['New Location'];
//Display result
echo "<h3>Item Found -</h3><p>";
echo "Asset Number: " . $AssetNo . "<p>";
echo "Serial Number: " . $SN . "<p>";
echo "Location (If booked out): " . $NewLocation . "<p>";
}
}
else{
echo "<p>Please enter a asset number to search..</p>";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Warehouse Asset Search [POC]</title>
</head>
<p><body>
<h3>Warehouse Search [POC]</h3>
<p>Search using the items asset number..</p>
<form method="post" action="warehouse\search.php" id="Search">
<input type="text" name="asset">
<input type="submit" name="submit" value="Search">
</form>
</body>
</html>
</p>