Forum Moderators: open
imbObj = []; function jsonObj(dir, image, prepend='') {
this.name = image;
this.uuid = prepend + dir;
} echo <<<EOF
<script>
EOF;
// $imgArr is an associative array that's created in PHP earlier
foreach ($imgArr as $dir => $image)
echo <<<EOF
imgObj.push(new jsonObj('$dir', '$image', 'dir_'));
EOF;
echo <<<EOF
</script>
EOF; [
null,
// it looks like this shows twice, regardless of how many times the push runs
{"0":{},"length":1},
{"0":{},"length":1},
{"name":"20221020_164047.jpg","uuid":"43f07ec4-17a7-4874-bb84-66a0f002f48e"},
{"name":"20221021_144704 (1).jpg","uuid":"71bba099-2616-4415-b420-0d0d16c19c30"}
] Is it possible that the inline JS echoed by your PHP runs at least once, prior to your javascript.js file loading and executing?
How do you "run the push()"?
var uploader = $('#fine-uploader-gallery').fineUploader({
...
})
.on('complete', function (event, id, uploadName, responseJSON) {
imgObj.push(new jsonObj(responseJSON['uuid'], uploadName));
}); Anyway, console.log() is your friend. Put it in the jsonObj() function, e.g. console.log(imgObj), and you'll see how often it is run and what the value of imgObj is at the time.
Please say that's a typo :)
javascript.js is cached pretty heavily via Apache settings and it's a pain to get it to load something new from the server