[eluser]misakitran[/eluser]
I use ajax jquery to update data, but always responded error.
---------- HTML ---------
Code:
<div class="Head">My bag (<span></span>)</div>
<form action="http://localhost:82/shop/product/add_to_cart" method="post" accept-charset="utf-8" class="CartForm">
<div class="Product">
<div class="Pic"></div>
<div class="Info">
<a class="Buy">Buy</a>
</div>
<input type="hidden" name="id" value="1">
</div>
</form>
---------- JS---------
$(document).ready(function() {
var link = "http://localhost:82/shop/product/"; // i am testing on local ^.^
$('a.Buy').click( function() {
form = $(this).parent().parent().parent();
form.submit();
});
$('form.CartForm').submit( function() {
// get id of product
var id = $(this).find('input[name=id]').val();
$.ajax({
type: 'POST',
url: link + 'add_to_cart',
data: { id: id },
success: function(respond) {
$('div.Head > span').html(respond);
},
error: function() {
$('div.Head > span').html('error'); // always respond here :(
}
});
return false;
});
});
---------- PHP ---------
function add_to_cart()
{
$id = $this->input->post('id');
if ($id != FALSE) {
echo $id;
}
else {
echo "false";
}
}
My problem is when submit, responding data always is 'error'.
Please help me ! Thanks !