I have a page that lazy loads photos via AJAX. Sometimes, as photos are loading, all session data is lost. It does not happen every time I load the page. I feel that I have ruled out session timeout/garbage collection as a cause. I also feel that I am returning the response from the AJAX requests correctly. The session ID is not changing, and the session cookie is not lost. All data saved to the session is simply gone. Does anyone have any ideas? I am using Laravel 4.1.28 and jQuery 1.8.0.
HTML snippet:
<tbody>
<tr>
<td class="photo-col" id="pidm-123456-photo-col"><img class="thumbnail" height="108" src="/shared/assets/img/idcardphotos/loading.gif" width="108"></td>
</tr>
<tr>
<td class="photo-col" id="pidm-234567-photo-col"><img class="thumbnail" height="108" src="/shared/assets/img/idcardphotos/loading.gif" width="108"></td>
</tr>
JavaScript:
$(document).ready(function() {
loadPhotos();
});
function loadPhoto(pidm) {
var img =
$('<img class="thumbnail" height="108" width="108">')
.attr('src', '/idcardphoto/' + pidm + '?thumbnail=true')
.load(function() {
$('#pidm-' + pidm + '-photo-col').html(img);
});
}
function loadPhotos() {
$('.photo-col').each(function() {
loadPhoto($(this).attr('id').split('-')[1]);
});
}
Route used by AJAX requests:
$this->app['router']->get('idcardphoto/{pidm}', ['as' => 'core::id_card_photo', function($pidm)
{
$thumbnail = (bool) Input::get('thumbnail');
$photo = '/path/to/idcardphotos/' . ($thumbnail ? 'thumbnails/' : '') . $pidm . '.jpg';
if (file_exists($photo))
{
return Response::make(file_get_contents($photo))->header('Content-Type', 'image/jpg');
}
$photo = '/shared/assets/img/idcardphotos/notavailable.gif';
return Response::make(file_get_contents($photo))->header('Content-Type', 'image/gif');
}])
->where('pidm', '[0-9]+');
Laravel session config:
return [
'driver' => 'file',
'lifetime' => 30,
'expire_on_close' => true,
'files' => storage_path().'/sessions',
'connection' => null,
'table' => 'sessions',
'lottery' => array(2, 100),
'cookie' => 'recreg_session',
'path' => '/',
'domain' => null,
'secure' => false,
];