Так работает:
let container_id = "#mp_offers_container_" + un_id;
$("#mp_button_" + un_id).click(function() {
let params_compare = $("#params_compare_" + un_id).val();
let bank_id = $("#bank_id_" + un_id).val();
let subscr_fee = $("#subscr_fee_" + un_id).val();
let payments_free = $("#payments_free_" + un_id).val();
let order_by = $("#order_by_" + un_id).val();
let ids = [];
$(container_id + " .mp_offers_add_to_compare input:checked").each(function() {
ids.push($(this).attr('data-tarif-id'));
});
if (ids.length == 0) {
ids = '';
}
$.post('/wp-content/themes/credits-pl/function/shortcodes_ajax.php',
{
name: "rko1",
id: ids,
bank_id: bank_id,
order_by: order_by,
subscr_fee: subscr_fee,
payments_free: payments_free,
params_compare: params_compare,
limit: '100',
geotargetting: 1
},
onAjaxSuccess
);
function onAjaxSuccess(data) {
$(container_id).html(data);
update_mp_data(container_id);
// Здесь мы получаем данные, отправленные сервером и выводим их на экран.
}
});
update_mp_data(container_id);
А так нет:
let container_id = "#mp_offers_container_" + un_id;
$("#mp_button_" + un_id).click(add_mp_data_run());
function add_mp_data_run() {
let params_compare = $("#params_compare_" + un_id).val();
let bank_id = $("#bank_id_" + un_id).val();
let subscr_fee = $("#subscr_fee_" + un_id).val();
let payments_free = $("#payments_free_" + un_id).val();
let order_by = $("#order_by_" + un_id).val();
let ids = [];
$(container_id + " .mp_offers_add_to_compare input:checked").each(function() {
ids.push($(this).attr('data-tarif-id'));
});
if (ids.length == 0) {
ids = '';
}
$.post('/wp-content/themes/credits-pl/function/shortcodes_ajax.php',
{
name: "rko1",
id: ids,
bank_id: bank_id,
order_by: order_by,
subscr_fee: subscr_fee,
payments_free: payments_free,
params_compare: params_compare,
limit: '100',
geotargetting: 1
},
onAjaxSuccess
);
function onAjaxSuccess(data) {
$(container_id).html(data);
update_mp_data(container_id);
// Здесь мы получаем данные, отправленные сервером и выводим их на экран.
}
}
update_mp_data(container_id);