简体   繁体   English

jQuery Ajax单击按钮不发送数据

[英]Jquery Ajax click button dont send data

This is my code for Javascript Ajax Jquery send data do purchase item. 这是我为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
  });

});

This is HTML code for submit. 这是要提交的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>

In PHP dont receive POST value -> 在PHP中不接收POST值->

if(isset($_POST['bookID']))
{
 $idProduct = $_POST['bookID'];

I think you should to define this code: 我认为您应该定义以下代码:

success: function (data) {
    console.log(data);
});

Replace of this code: 替换此代码:

success: function (data) {
    alertify.alert("This item was add to your cart.", function(){
    alertify.message('OK');
});

Now you see what result you get in the console. 现在,您将在控制台中看到什么结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM