I have a problem when passing the data to php using jquery .post.
Html
<div class="wrp">
<h1>Product <? echo $pd['Product']['name'] ?></h1>
<input id="qty" type="text" name="qty">
<input id="add" type="button" value="Add to cart">
</div>
<script type="text/javascript">
$(document).ready(
function()
{
$('#add').click(function()
{
$.post(
'/shop/addtocart',
{
qty : ('#qty').val();
},
function(data){
alert(data);
}
)
}
);
}
);
</script>
and the /shop/addtocart function
public function addtocart(){
if($this->request->is('ajax')){
$qty = $_POST['id'];
echo $qty;
}
}
and when I click it alerts me the desired value but after the value it echoes the whole html code.
Please help!