I´m kind of new to using Ajax but I am trying to update the value of a session using Ajax. The Ajax call shoud fires when clicked on a button.
When I click on this button it also returns the succes function. I am using Wordpress with this Ajax call.
Currently this is my code:
Ajax call:
$('.button').click(function(){
$.ajax({
type: "POST",
url: "/wp-admin/admin-ajax.php",
data: {click: "true"},
success: function() {
alert('bro it worked!');
}
});
});
functions.php in Wordpress: session_start();
function notificationCall() {
$_SESSION['clicked'] = $_POST['click'];
die();
}
add_action('wp_ajax_notificationCall', 'notificationCall');
add_action('wp_ajax_nopriv_notificationCall', 'notificationCall');
echo $_SESSION['clicked'];
So my Ajax call returns the succes function containing a string with "Bro it worked". However, my session always stays my same default value of "false".
Any ideas?