I have spent two days trying to get the issue resolved, but can't get it done.
I am sending session stored in browser through jQuery AJAX to PHP function so that to save the data to Wordpress db.
in session Storage data is stored like this -
so this without success:
var dataStorage = JSON.stringify(sessionStorage.getItem('shoppingCart'));
$.ajax({
url: "https://mywebsite.com/wp-admin/admin-ajax.php",
method: "POST",
data: 'globalvar='+dataStorage+'&action=myfunction',
dataType: "json"
}).done(function (response) {});
the PHP function is:
if (!function_exists('myfunction')) {
function myfunction() {
$object = $_POST['globalvar'];
$decoded_object = json_decode($object);
//wordpress update db
update_post_meta('42393', 'menu_items_list', $menu_make_arr);
}
add_action('wp_ajax_myfunction', 'myfunction');
add_action('wp_ajax_nopriv_myfunction', 'myfunction');
}
I get null in db like this


data: 'globalvar='+encodeURIComponent(sessionStorage)+'&action=myfunction'sessionStoragevariable would beshoppingCart.