Answer the question
In order to leave comments, you need to log in
Element not found AJAX catalog.element reasons?
Good day! I didn’t think that I would ask for help myself, but I got into a very interesting situation. Implemented a pop-up window in the online store, which is loaded using the "buy" button. Everything works great, except for one moment ... Sometimes, if you press the "buy" button again, it gives an error saying "Element not found". Exactly like a random product. But if you press the same button again, after several attempts, the modal window will still be loaded. I thought that the whole thing was in the modal window, but upon closing, I implemented the removal of data from it in order to AJAX pull up new values. Below is a video demonstrating the problem.
Implementation description:
An additional catalog.top element is displayed in catalog.element, which contains a fully working implementation.
Also, there is a single pop-up in which data is entered using the following construction:
orderButton.on('click', function () {
let productId = $(this).attr("data-button-buy-id");
$("#genElement").load("/api/v1/products.php?ID=" + productId, function (responseText, textStatus, XMLHttpRequest) {
if (textStatus === "success") {
$("#productLoader").hide(); // Скрываем spinner
initializeScripts(); // Инициализируем нужные нам для catalog.element скрпиты (временный костыль)
}
});
});
$("#centralModalLg").on('hide.bs.modal', function (e) {
$("#productLoader").show(); // Возвращаем spinner в привычное состояние (временный костыль)
$("#genElement").empty(); // Очищается pop-up от данных внутри него
});
<?php
require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php');
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();
/** @global CMain $APPLICATION */
/** @var string $componentPath */
/** @var CBitrixComponent $component */
$productID = $_GET['ID'];
if (!isset ($productID))
die ('Не получен параметр ID');
$APPLICATION->IncludeComponent(
"bitrix:catalog.element",
"modal-element",
array(
"ACTION_VARIABLE" => "act",
"DETAIL_PICTURE_MODE" => array(
0 => "POPUP",
1 => "MAGNIFIER",
),
"DISABLE_INIT_JS_IN_COMPONENT" => "Y",
"DISPLAY_NAME" => "Y",
"ELEMENT_ID" => $productID,
"IBLOCK_ID" => "5",
"IBLOCK_TYPE" => "catalog",
"IMAGE_RESOLUTION" => "16by9",
"MAIN_BLOCK_PROPERTY_CODE" => array(
0 => "ARTNUMBER",
1 => "BRAND",
2 => "COLOR",
3 => "MATERIAL",
4 => "MORE_PHOTO",
5 => "ADDITIONAL_FILES",
6 => "AMOUNT",
7 => "AMOUNT_EUROPE",
),
"OFFERS_SORT_FIELD" => "sort",
"OFFERS_SORT_FIELD2" => "id",
"OFFERS_SORT_ORDER" => "asc",
"OFFERS_SORT_ORDER2" => "desc",
"OFFER_ADD_PICT_PROP" => "-",
"PARTIAL_PRODUCT_PROPERTIES" => "N",
"PRICE_CODE" => array("BASE"),
"PRICE_VAT_INCLUDE" => "Y",
"PRICE_VAT_SHOW_VALUE" => "N",
"PRODUCT_ID_VARIABLE" => "id",
//"SECTION_ID" => $_REQUEST["SECTION_ID"],
"SECTION_ID_VARIABLE" => "SECTION_ID",
"COMPONENT_TEMPLATE" => "modal-element"
),
false
);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question