douba9776 2014-12-24 14:42
浏览 15

我没有收到来自ajax请求的回复

I am getting no response from ajax request . i am posting a ajax call to processor.php file and the processor.php file is processing the file and sending the processed file back to javascript i am gerring my result in my console log but it is not showing in the html. My javascript code is :

function add_to_cart(item_name,item_price){
  $('.user-info').slideUp('1200');
  $('.cart-status').slideDown('1200');

  var dataString = "item_name=" + item_name + "&item_price=" + item_price + "&page=add_to_cart";
  $.ajax({
    type: "POST",
    url: "php/processor/processor.php",
    data:dataString,
    beforeSend:function(){
      $(".cart-show-product").html('<h3>Your Cart Status</h3><img src="images/loading.gif" align="absmiddle" alt="Loading...." class="center" /><br><p class="center">Please Wait...</p>');
    },
    success: function(response){
      console.log(response);
      $(".cart-show-products").html(response);
    }
  });
}

and my php is :

if(isset($_POST['item_name']) && !empty($_POST['item_name']) && isset($_POST['item_price']) && !empty($_POST['item_price']))
{
  $sql = mysqli_query($conn, 
      'SELECT * FROM 
        products_added 
        where 
        username = "'.mysqli_real_escape_string($conn, $_SERVER['REMOTE_ADDR']).'" 
        and 
        item_added="'.mysqli_real_escape_string($conn, $_POST['item_name']).'"'
);
if(mysqli_num_rows($sql) < 1)
{
  mysqli_query($conn, 
        "INSERT INTO products_added values(
          '', 
          '".mysqli_real_escape_string($conn, $_SERVER['REMOTE_ADDR'])."', 
          '".mysqli_real_escape_string($conn, $_POST['item_name'])."', 
          '".mysqli_real_escape_string($conn, $_POST['item_price'])."', 
          '".mysqli_real_escape_string($conn, '1')."', 
          '".mysqli_real_escape_string($conn, $_POST['item_price'])."'
          '".mysqli_real_escape_string($conn, date("d-m-Y"))."')"
  );
?>
<table class="cart-show-products">
  <thead>
    <tr>
      <td>Sl.No</td>
      <td>Item</td>
      <td>Qty</td>
      <td>Price</td>
      <td>Action</td>
    </tr>
  </thead>
<tbody>
<?php
  $sl_no = 1;
  $sql = mysqli_query(
          $conn, 
          'SELECT sum(amount) as grandtotal
                FROM products_added
                WHERE username = "'.mysqli_real_escape_string($conn, $_SERVER['REMOTE_ADDR']).'"
                ORDER BY id'
  );
  $row = mysqli_fetch_array($sql);
  $grandtotal = strip_tags($row['grandtotal']);
  $sql = mysqli_query(
                $conn, 
                'SELECT 
                id,
                item_added,
                price,
                quantity
                FROM products_added
                WHERE username = "'.mysqli_real_escape_string($conn, $_SERVER['REMOTE_ADDR']).'"
                ORDER BY id'
  );
  $row = mysqli_fetch_array($sql);
  $item_id = strip_tags($row['item_id']);
  $item_name = strip_tags($row['item_added']);
  $item_price = strip_tags($row['price']);
  $quantity = strip_tags($row['price']);
  ?>
    <tr class="items_wrap items_wrap<?php echo $item_id; ?>">
      <td><?php echo $sl_no++; ?></td>
      <td><?php echo $item_name ?></td>
      <td><?php echo $quantity ?></td>
      <td><?php echo $item_price ?></td>
      <td><a href="javascript:void(0);" class="remove-from-cart" onclick="remove_this_item('<?php echo $item_id; ?>')"><i class="fa fa-times"></i></a></td>
    </tr>
  </tbody>
</table>
<?php
}
  • 写回答

2条回答 默认 最新

  • douzhong5902 2014-12-24 15:02
    关注

    If this is your actual code, then you have a syntax error in your PHP file. There are a missing close bracket for:

    if(isset($_POST['item_name']) && !empty($_POST['item_name']) && isset($_POST['item_price']) && !empty($_POST['item_price']))
    

    The second problem is, you are not print anything, if this condition has failed.

    Note

    You do not need to use isset, if you are checking empty. empty will return false, if the variable not set.

    You can debug your respons by check NET tab in your web developer tools, or see, what is the response of the AJAX.

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?