Forum Moderators: martinibuster
// This is probably irrelevant, but just in case... I do have a header banner
// that loads, so I'm confident nothing here is messed up
<script async src="https://www.googletagservices.com/tag/js/gpt.js"></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
var slot = new Array();
googletag.cmd.push(function() {
googletag.pubads().enableSingleRequest();
googletag.pubads().disableInitialLoad();
googletag.enableServices();
});
</script>
// This is the part that is relevant...
<script>
function showData(data_b) {
var n = 2;
if (data_b == 2) n = 1;
for (i=1; i <= n; i++) {
if (('#data_b_' + data_b).length) {
// This shows up in all iterations
$('#data_b_' + data_b).append(data_b);
googletag.cmd.push(function() {
// This does NOT show up on data_b = 2, but shows up on all others. So
// for some reason, googletag.cmd.push() fails on the first iteration
$('#data_b_' + data_b).append(data_b);
// This doesn't work on data_b = 2 OR data_b = 3, but does on all others
slot[data_b] = googletag.defineSlot('/xxxx/Medium_Rectangle',
[300, 250], 'data_b_' + data_b).
addService(googletag.pubads());
googletag.display('data_b_' + data_b);
googletag.pubads().refresh([slot[data_b]]);
});
}
data_b++;
}
}
</script>
// Then, later in PHP... the first loop is on the page, then the rest are in
// an infinite scroll. So data_b = 2 is embedded on the page, then 3+ is
// in an Ajax fragment. But since 2 is the one NOT working, I didn't include
// the infinite scroll coding
$data_b = 2;
for ($i = 0; $i < 10; $i++) {
if ($i > 0 && ($i / 5 == intval($i / 5))) {
$data_b++;
echo <<<EOF
<div id="data_b_$data_b"></div>
<script>
showData($data_b);
</script>
EOF;
}
}
setTimeout("showData($data_b)", 100); $(function() { showData($data_b); });