V
V
VladPolanski2018-03-20 15:41:25
1C-Bitrix
VladPolanski, 2018-03-20 15:41:25

How to make an AJAX request to delete a product?

Hello. Tell me please. Here is the code for removing a product from the page deferred
Ajax

$('.delay').click(function(){
    var deletebasketid = $(this).attr('id');
    ajaxpostshow("/ajax/delete.php", deletebasketid, ".col-sm-1-5" );           
    return false;
 });

Sample
<?foreach($new_arr as $key => $value){?>
    <div class="col-sm-1-5">
  <p><a href="/?action=delete&id=<?=$value['ID'];?>" class="delay" id="ajaxaction=delete&ajaxdeleteid=<?=$value['ID'];?>">
<span class="delete"></span>Удалить</a></p>
  <a href="<?=$value["DETAIL_PAGE_URL"]?>">
    <div class="goods">
      <div class="goods-description"><p><?=$value['NAME']?></p></div>
        <div class="price text-center">
          <span class="new-price"><?=$value["PRODUCT_PRICE_ID"]?> руб.</span>
        </div>
      </div>
    </a>
  </div>
<?}?>

when you click on the Delete button, all products from the pending ones are deleted, the page is completely cleared, and when the page is reloaded, it already works - there is no deleted product, the rest are.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lone Ice, 2018-03-20
@daemonhk

ajaxpostshow("/ajax/delete.php", deletebasketid, ".col-sm-1-5" );

Is ".col-sm-1-5" supposed to be the element to be removed? So you delete them all, but you must delete the one from which the request came, for example, the simplest - var parent=$(".delay").parents(".col-sm-1-5"); and then this parent and feed your ajaxpostshow function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question