Answer the question
In order to leave comments, you need to log in
How do you make AJAX architectural decisions?
There is a table with a list of orders of the form
Order number | Name of the customer | Product name | Date |
This table, for example, is displayed by the bitrix component, from the database or via the REST API, it does not matter.
<div id="#orders-block">
$APPLICATION->IncludeComponent(
"d6core:custom.order.list",
"orders_list",
Array(
'PARAMS' => $date,
),
);
</div>
$("#orders-filter-form").submit(function (e) {
e.preventDefault();
var form = $(this);
var url = form.attr('action');
$.ajax({
type: 'POST',
url: url,
dataType: 'json',
data: form.serialize(),
beforeSend: function () {
$('#orders-block').html('Прелоадер....');
},
}).done(function (response) {
$("#orders-block").html(response);
}).fail(function (jqXHR, textStatus) {
console.log(jqXHR, textStatus);
});
});
<?php require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");
use Bitrix\Main\Context;
$request = Context::getCurrent()->getRequest();
if ($request->isPost() && $request->isAjaxRequest() && $GLOBALS['USER']->IsAuthorized()) {
$data = json_decode($request['data'] ,true);
$date = Helper::clean($data['date']);
ob_start();
$APPLICATION->IncludeComponent(
"d6core:custom.order.list",
"orders_list",
Array(
'PARAMS' => $date,
),
);
$view = ob_get_contents();
ob_end_clean();
Helper::jsonResponse([
'view' =>$view,
'type' => 'ok'
]);
}
class Helper {
//json ответ
static function jsonResponse(array $result)
{
$response = new \Bitrix\Main\Engine\Response\Json($result);
$response->send();
}
//фильтрует данные
static function clean($value = "")
{
$value = trim($value);
$value = stripslashes($value);
$value = strip_tags($value);
$value = htmlspecialchars($value);
return $value;
}
}
Answer the question
In order to leave comments, you need to log in
To what extent is such a decision acceptable?
Are there any more correct, flexible architectural solutions?
Of course, IS issues are also of interest here.
Then the question is, why do such a wrapper if I can stupidly pull data from $_POST directly?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question