I am facing a problem in getting session data in Magento 2, when I deploy my Build on 2 Web-Servers. I am facing no issue on Single Web-Server.
Problem Details I am setting some data in session, in first AJAX request, and then getting that data in the next consecutive AJAX request but the session returns no values.
AJAX-Request Format:
jQuery.ajax({
url: myUrl,
type: 'POST',
dataType: 'json',
data: myData,
cache: false,
})
Problem Resolution Approaches
Printed overall session data and found empty customer data. Only the following data is returned.
Array([customer_segment_ids] => Array([1] => Array([0] => 3))[wishlist_item_count] => 0)
Tried to load session data using ObjectManager, while created object of
\Magento\Customer\Model\Session
and provided the SessionID to get data from the Database-Table using my custom code, but it returned empty array.Tried to load session data using MySQL Custom Query by SessionID on that table and got data.
Changed Session storage to Redis in my
app/etc/env.php
file, as directed here, but got the same empty session issue.Changed Session storage to Files in my
app/etc/env.php
file and I got the correct data as expected.
Can I have a solution for this problem?