I am passing PHP sessions to variables to use in Jquery code. Below, there are four areas where I invoke the console log. Console log numbers 1 and 3 reflect the value of the variables no problem. 2 and 4 do not. I needed #4 to have value so I can use the variables in conditions. I guess this could be a scope issue, but I don't see why. Looking for some guidance.
<script type="text/javascript">
// GET VARIABLES THROUGH PHP SESSSION
customerType = '<?php echo $customerType; ?>';
myClicks = '<?php echo $myClicks; ?>';
email = '<?php echo $email; ?>';
console.log('1 ' + email);
console.log('1 ' + myClicks);
console.log('1 ' + customerType);
//SET NUMBER OF ROWS TO DISPLAY AT A TIME
$(document).ready(function () {
rowsPerPage = 5;
// GETTING DATA FROM FUNCTION BELOW
getData();
$('#load-more').click(function () {
console.log('2 ' + email);
console.log('2 ' + myClicks);
console.log('2 ' + customerType);
$('#load-more').html('Loading...');
var rowID = Number($('#row-id').val());
var allCount = Number($('#count').val());
rowID += rowsPerPage;
if (rowID <= allCount) {
$('#row-id').val(rowID);
getData();
} else {
$('#load-more').html('End Of Data');
//$('#load-more').html('');
}
});
/* REQUEST DATA */
function getData () {
console.log('3 ' + email);
console.log('3 ' + myClicks);
console.log('3 ' + customerType);
var rowID = $('#row-id').val();
var allCount = $('#count').val();
$.ajax({
url: 'promotions/newest-load-button-data.php',
type: 'post',
data: {
rowID: rowID,
rowsPerPage: rowsPerPage
},
dataType: 'json',
success: function (response) {
setTimeout(function () {
loadData(response);
$('#load-more').html('Load More');
}, 1000);
}
});
}
/* LOAD DATA TO PAGE */
function loadData (data) {
console.log('4 ' + email);
console.log('4 ' + myClicks);
console.log('4 ' + customerType);
var dataCount = data.length;
for (var i = 0; i < dataCount; i++) {
if (i == 0) {
var allCount = data[i]['allcount'];
$('#count').val(allCount);
} else {
var promoID = data[i]['promoid'];
var promoName = data[i]['promoname'];
var promoRefNum = data[i]['promorefnum'];
var promoType = data[i]['promotype'];
var theBanner = data[i]['thebanner'];
// Here I will use conditions based on email, customerType, and myClicks
if (promoType == 'Banner') {
$('#load-container').append('<div class="row-center-center padding-top-5 padding-bottom-2"><div>' + promoName + '</div></div>');
$('#load-container').append('<div><div class="wrap-content"><img class="mobile-banner-scale" id="visitor-banner-click" src=' + theBanner + '></div></div>');
}
if (promoType == 'Video Banner') {
$('#load-container').append('<div class="row-center-center padding-top-5 padding-bottom-2"><div>' + promoName + '</div></div>');
$('#load-container').append('<div><video class="mobile-video-size" id="visitor-banner-click" src=' + theBanner + ' autoplay muted loop></video></div>');
}
}
$('#load-more').html('Load More');
}
}
});
</script>