Код: Выделить всё
add_action('wp_ajax_uipp_get_button_content', 'uipp_get_button_content');
add_action('wp_ajax_nopriv_uipp_get_button_content', 'uipp_get_button_content');
function uipp_get_button_content() {
if (!isset($_POST['button_id']) || !is_numeric($_POST['button_id'])) {
wp_send_json_error(['message' => 'Invalid button ID.']);
}
$button_id = intval($_POST['button_id']);
$button_content = apply_filters('the_content', get_post_field('post_content', $button_id));
if (!$button_content) {
wp_send_json_error(['message' => 'Content not found.']);
}
wp_send_json_success(['content' => $button_content]);
}
< /code>
, а затем попытка распечатать полученный контент на странице с: < /p>
fetch(ajax_object.ajax_url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
action: "uipp_get_button_content",
button_id: button_id,
}),
})
.then(response => response.json())
.then(data => {
if (data.success) {
revealContainer.innerHTML = data.content;
console.log(data.content);
} else {
revealContainer.innerHTML = `
Error: ${data.message}
`;
}
})
.catch(error => {
revealContainer.innerHTML = "
Failed to load content.
";
});
Введите описание изображения здесь < /p>
Ничего в консоли в пути ошибок - error_log и debug_log пусты! Из HTML, стилей, сценариев, сценариев, который может быть вмешательством в содержимый содержимого.
Код: Выделить всё
wp_send_json_success(['content' => $button_content]);< /code>
с:
wp_send_json_success(['content' => "Hello"]);Такая же проблема, все еще не определенная.
Подробнее здесь: https://stackoverflow.com/questions/795 ... -undefined
Мобильная версия