这是我的代码,用于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值 - &gt;
if(isset($_POST['bookID']))
{
$idProduct = $_POST['bookID'];
答案 0 :(得分:0)
我认为您应该定义此代码:
success: function (data) {
console.log(data);
});
替换此代码:
success: function (data) {
alertify.alert("This item was add to your cart.", function(){
alertify.message('OK');
});
现在您可以看到您在控制台中获得的结果。