Answer the question
In order to leave comments, you need to log in
AJAX. Why does the entire document come back?
Hello.
Task: It is necessary to make the implementation of adding messages without reloading the page.
Decision:
function mode(){
$.ajax({
url: location.href,
success: function(data) {
$('#result_form').html(data);
}
});
};
var message;
function mess_add(){
var objForms = document.forms.ajax_form[0].name + "=" + document.forms.ajax_form[0].value;
message = getXmlHttpRequest();
message.open("POST", location.href, false);
message.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
message.onreadystatechange = function(){
if(message.readyState == 4){
if(message.status == 200){
mode();
}
}
}
message.send(objForms);
}
if(isset($_POST["comments_text"])){
CModule::IncludeModule('iblock');
$elCom = new CIBlockElement;
$PROP = array();
$PROP["COMMENTS"] = $_POST["comments_text"];
$PROP["USER_AUTHOR"] = $USER->GetID();
$PROP["ID_EVENT"] = $arResult["ID"];
$fieldsComments = Array(
"DATE_CREATE" => date("d.m.Y H:i:s"), //Передаем дата создания
"CREATED_BY" => $USER->GetID(),
"IBLOCK_ID" => 33,
"PROPERTY_VALUES"=> $PROP,
"NAME" => "unknow",
"ACTIVE" => "Y", // активен
);
$IDcom = $elCom->Add($fieldsComments);
if($IDcom){
// LocalRedirect("/youdo/event_view/detail.php?ID=".$arResult["ID"]);
}
}
<div id="result_form">
<table style="width: 100%;">
<? $arSelect = Array("ID", "IBLOCK_ID", "DATE_CREATE");
$arFilter = Array("IBLOCK_ID" => 33, "ACTIVE"=>"Y", "PROPERTY_ID_EVENT" => $arResult["ID"]);
$res = CIBlockElement::GetList(Array(), $arFilter, false, Array(), $arSelect);
while($final_array = $res->GetNextElement()){
$arFields = $final_array->GetFields();
$arProps = $final_array->GetProperties();
$rsUser = CUser::GetByID($arProps["USER_AUTHOR"]["VALUE"]);
$arUser = $rsUser->Fetch();
$arImage = CFile::GetPath($arUser['PERSONAL_PHOTO']);?>
<tr>
<td rowspan="2" style="width: 110px;"><?if(!empty($arImage)):?><img src="<?=$arImage;?>" alt=""><?else:?><img src="<?=CUtil::GetAdditionalFileURL(SITE_TEMPLATE_PATH.'/image/user.png')?>" alt=""><?endif;?></td>
<td style="color: #343F4B;"><?=$arUser["NAME"]." ".$arUser["LAST_NAME"];?></td>
<td style="width: 15%; text-align: right; font-size: 12px; color: silver;"><?=$arFields["DATE_CREATE"];?></td>
</tr>
<tr>
<td colspan="2" style="color: #8492A6;"><?=$arProps["COMMENTS"]["VALUE"];?></td>
</tr>
<?}?>
</table>
</div>
<form action="" method="get" id="form_message_add">
<input type="text" name="message">
<button onclick="send_message()">Отправить</button>
</form>
Answer the question
In order to leave comments, you need to log in
restartbuffer
https://dev.1c-bitrix.ru/support/forum/forum6/topi...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question