- firstpage
Код: Выделить всё
Open New Tab With SESSION
var priceSlider = document.getElementById("priceRange");
var test = document.getElementById("checkme");
function updatePrice() {
test.value = priceSlider.value;
}
updatePrice();
$(document).ready(function() {
$('#button').click(function() {
$.ajax({
type: 'POST',
url: `${window.location.origin}/wp-admin/admin-ajax.php`,
data: { action: 'set_session_variable', buttonValue: test.value },
success: function(response) {
console.log('SESSION set successfully');
console.log(test.value);
}
});
});
Код: Выделить всё
function set_session_variable() {
session_start();
$variable_value = $_POST['buttonValue'];
$_SESSION['buttonValue'] = $variable_value;
wp_send_json_success();
}
add_action('wp_ajax_set_session_variable', 'set_session_variable');
add_action('wp_ajax_nopriv_set_session_variable', 'set_session_variable');
function session_initialize() {
if ( ! session_id() ) {
session_start();
}
}
add_action( 'init', 'session_initialize' );
- вторая страница
В плагине WP CODER у меня есть файл .php:
Код: Выделить всё
session_start();
echo $_SESSION['buttonValue'];
Код: Выделить всё
[wp_code id="1"]
Спасибо;)
Подробнее здесь: https://stackoverflow.com/questions/787 ... to-another
Мобильная версия