salve signori parto con la premessa che non ho molta dimestichezza con javascript... vi spiego.
sparo con una pistola di codice a barre su un barcode... il valore di questo barcode dovrebbe essere riportato su un campo imput text..clicco poi sul bottone input con id submit e dovrebbe andare a fare quello che sta scritto su index2.php (ovvero selezionarmi all'interno del database quel record che ha come codice prodotto lo stesso valore del barcode inviato)..il problema sta quando clicco sul bottone di submit... non succede nulla, rimane tutto fermo!! c'è qualcosa che non va con lo script? vi posto qua sotto i codici
HTML
codice HTML:
<head>
<script type='text/javascript' src='barcode.js'></script>
</head>
<body>
<div style='position: absolute; top:20%; width: 100px;'>
<input type='text' id='barcode' name='barcode' placeholder='BarCode'>
<input type='submit' id='submit' name='sendbarcode' placeholder='sendbarcode'>
</div>
</body>
</html>
barcode.js
codice:
$(document).ready(function(){
$("#submit").click(function(){
var barcode = $("#barcode").val();
$.post("index2.php",
{
barcode: barcode
},function(data,status){
alert(status);
});
});
});
index2.php
codice:
header("Content-type: text/html; charset=ISO-8859-1");
$link = mysqli_connect("localhost", "xxxxxx", "xxxxxx", "xxxxxx");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$barcode = $_GET['barcode'];
$sql = "SELECT * FROM inventario WHERE Cod_prodotto='$barcode'";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='center'>";
echo "<tr>";
echo "<th>Cod.prodotto</th>";
echo "<th>Categoria prodotto</th>";
echo "<th>Descrizione</th>";
echo "<th>Immagine</th>";
echo "<th>Prezzo unitario</th>";
echo "<th>Quantita' rimaste</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['Cod_prodotto'] . "</td>";
echo "<td>" . $row['Categoria'] . "</td>";
echo "<td>" . $row['Descrizione'] . "</td>";
echo "<td><img src='data:image/jpeg;base64,".base64_encode($row['Img'])."'/></td>";
echo "<td>" . $row['Prezzo_unitario'] . "</td>";
echo "<td>" . $row['Quantita_rimaste'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_free_result($result);
} else{
echo "";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);