1
I am unable to send the value of an input to another php page.
On my products.php page I do a database search and upload the page show_itemswithin a div. When loading the data into this div, I mount an input. This "input: deflarg" that I am unable to send to the.php cart
part of the code...show_items.php
echo '<tr>';
echo '<td height="45">'."Definir a Largura da Porta: ".'<input type="text" name="deflarg" id="deflarg" size="5" maxlength="5"/>'. " cm".'</td>';
echo '</tr>';
echo '<tr>';
//echo '<td height="45">' . '<input type="submit" name="comprar" value="COMPRAR"/>'.'</td>';
//echo '<td height="45">' . '<a href="carrinho.php?acao=add&id='.$linha["id"].'">Comprar</a>'.'</td>';
echo'<td height="45">' . '<a href="carrinho.php?acao=add&id='.$id.'">
<img src="img/comprar-1.png" id="add_car" height="70" width="200" align="center" title="Adicionar ao Carrinho"></a>'.'</td>';
echo '</tr>';
Inside the page_item I am using this jquery + Ajax, but without success.
<script type="text/javascript">
$(document).ready(function(){
$("#add_car").click(function(e){
if($("#deflarg").val()==""){
alert("Ôpa!!! " + "Você esqueceu de digitar a largura!");
e.preventDefault();
}
$.ajax({
url: 'carrinho.php',
type: 'POST',
data: $('enviar_para_carrinho').serialize(),
success: function(data){
$('#deflarg').html(data);
}
});
});
});
</script>
On the cart page.php, I’m doing so:
<?php
$largura = $_POST["deflarg"];
echo "Largura: " . $largura;
?>
Where am I going wrong ?
See if Ajax is reading the data before sending. Make a console.log() of this
$('enviar_para_carrinho').serialize()
to see if the data is there.– Sam
That one
$('.enviar_para_carrinho')
is the tag class<form>
?– Sam