Это мой код для Javascript Ajax Jquery отправить данные сделать покупку.
$('.reserve-button').click(function(e){
var book_id = $(this).parent().data('id');
e.preventDefault();
$.ajax({
url: "/php/insertpurchase.php",
type: "POST",//type of posting the data
data: {"bookID": book_id},
success: function (data) {
alertify.alert("This item was add to your cart.", function(){
alertify.message('OK');
});
},
error: function (result, status, err) {
console.log('error', err, status);
},
timeout : 15000//timeout of the ajax call
});
});
Это HTML-код для отправки.
<div class="col-md-4">
<?php $bookID = $row['id'];?>
<div class= "obutton feature2" data-id="<?php echo $bookID;?>">
<button class="reserve-button"><?php echo $row['price'];?></button>
В PHP не получают значение POST ->
if(isset($_POST['bookID']))
{
$idProduct = $_POST['bookID'];
Я думаю, что вы должны определить этот код:
success: function (data) {
console.log(data);
});
Заменить этот код:
success: function (data) {
alertify.alert("This item was add to your cart.", function(){
alertify.message('OK');
});
Теперь вы видите, какой результат вы получите в консоли.
Других решений пока нет …