Answer the question
In order to leave comments, you need to log in
How to pass in an Ajax request an array of the current element formed by the PhpToJSObject method?
Hello connoisseurs!
Who will tell you how to pass the array of the current element in the Ajax request. You can make it easier and push the script into the foreach loop, but I want to limit myself to the script outside the loop. I also tried to push this array into a hidden input with the assignment id="item_<?= $arItem["ID"]; ?>" , and get it like this:
var ID = $(this).attr('id'); // Берется из id кликнутого элемента
var ITEM = $('#item_' + ID); // Собственно сам скрытый инпут с подстановкой полученного id
$rsItemJS = array(
"ID" => $arItem["ID"],
"NAME" => $arItem["NAME"],
"PROPERTIES" => $arItem["PROPERTIES"]
);
$arItemJS = CUtil::PhpToJSObject($rsItemJS);
$(document).ready(function ($) {
$('.item').on('click', function () {
var ITEM = <?= $arItemJS ?>;
var AjaxSelectItem = {ITEM: ITEM};
ajaxrequest('/include/popup.modal.php', AjaxSelectItem , ' .modal-body');
return false;
});
});
function ajaxrequest(url, param, content) {
$.ajax({
type: "POST",
url: url,
data: param,
success: function (response) {
$(content).html(response);
}
});
}
Answer the question
In order to leave comments, you need to log in
Bringing elements to the front:
...
<div class="item" data-id="<?= $arItem['ID'] ?>" > тут всякое </div>
...
$('.item').click(function() {
ajaxrequest('/include/popup.modal.php', {item_id: $(this).data('id')} , ' .modal-body');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question