Answer the question
In order to leave comments, you need to log in
Update item active date?
Tell me, I'm changing the date of the element's activity, but when you click on the link, it changes for all elements, how to make it change for the one that was clicked.
<? foreach ($arResult["ITEMS"] as $arItem):?>
<a class="up-your-ads-icon" href="#" id="go" onclick="
<?
$newEl = new CIBlockElement;
$elProps
= array(
"MODIFIED_BY" => $USER->GetID(),
"IBLOCK_ID" => 3,
"ACTIVE_FROM" => ConvertTimeStamp(time(), "FULL"),
"ACTIVE" => "Y",
);
$res = $newEl->Update($arItem['ID'], $elProps);
?> "><?=$arItem['ID']?></a>
<? endforeach ?>
Answer the question
In order to leave comments, you need to log in
In general, everything is in Google, it seems you have not tried to google
$(".update").click(function(event) {
var id = $(this).attr('data-id');
$.ajax({
url: '/path/to/file',
type: 'post',
data: {id: id},
})
.done(function() {
console.log("success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
});
<?
include($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");
if(\Bitrix\Main\Loader::includeModule('iblock')) {
$newEl = new CIBlockElement;
$elProps = array(
"MODIFIED_BY" => $USER->GetID(),
"IBLOCK_ID" => 3,
"ACTIVE_FROM" => ConvertTimeStamp(time(), "FULL"),
"ACTIVE" => "Y",
);
$res = $newEl->Update($_REQUEST["id"], $elProps);
}
You have absolutely no understanding of PHP or JavaScript syntax. Since you are calling - you are updating all the entries in the $arResult["ITEMS"] array. In order to perform an action on click, you must either describe a function for click / onclick that will send an asynchronous request to the server to update the element. Or, on click, submit the form with reloading the page to perform this action.
I advise you to read as an example of implementation .
Help, I made a request, put it in a file, but the date does not change. What's wrong?
$("#go a").click(updateElement)
function updateElement()
{
$.ajax({
url: "/local/ajax/edit-ads2.php",
type: "POST",
data: requestData,
cache: false,
dataType: 'html',
processData: false,
contentType: false,
success: function (data) {
$('.my-ads-list-container .ads-date').html(data)
$('#go').show;
},
error: function (error) {
console.log('error', error);
}
});
}
<?
include($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");
$newEl = new CIBlockElement;
$elProps
= array(
"MODIFIED_BY" => $USER->GetID(),
"IBLOCK_ID" => 3,
"ACTIVE_FROM" => ConvertTimeStamp(time(), "FULL"),
"ACTIVE" => "Y",
);
$res = $newEl->Update($arItem['ID'], $elProps);
Namco
Alexey Zakharov wrote the correct answer to you.
I'll just add this:
foreach( $arResul['ITEMS'] as $arItem)
{
?><a class="update" data-id='<?=$arItem['ID']?>' href="">Ссылка примерного вида</a><?
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question