M
M
mills2021-03-27 13:29:08
JavaScript
mills, 2021-03-27 13:29:08

Why is the ajax request not coming from the form?

Hello!
In the product card, 1C-Bitrix made a form for sending ajax adding a session for subsequent work with it, but for some reason, sending does not work in the product card...
Can anyone tell me what the problem is? It works in another place, but there is no product in the card, the solution is aspro max.

The form:

<form id="cp_form_add" enctype="multipart/form-data" method="POST">
  <input id="count" type="hidden" name="cont" value="1" />
  <input id="id_user" type="hidden" name="id_user" value="<?=$USER->GetID();?>" />
  <span id="id_items_cp"><input id="id_product" type="hidden" name="id_product" value="<?=$arResult['ID']?>" /></span>
  <br>
  <div class="addpc">
    <a class="btn btn-default has-ripple" id="basket_cp" type="submit" name="hitAdd">Добавить в КП</a>
  </div>
</form>


Script
$(function() {
  $("#cp_form_add").submit(function () {
    var form_name = $(this).serialize();
    $.post({
      processData: false,
      contentType: false,
      cache: false,
      url: '/ajax/add_cp/',
      type: "POST",
      data: form_name,
      success: function (response) {
        $('.addpc').html('<a class="btn btn-default has-ripple" id="basket_ok" type="submit" name="hitAdd">Товар добавлен</a>');
      }
    });
  });
});

$(function() {
  $('#basket_cp').click(function(){
    event.preventDefault();
    $("#basket_cp").submit();
  });
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Gritsuk, 2021-03-27
@winer

Place the PHP code that processes the data from the form outside of template.php and result_modifier.php. The code placed there is cached.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question