I have a PHP file uploader that needs to trigger a Javascript function to update a jQuery Sortable container after the upload is finished. At the moment, it does not seem to work. What am I doing wrong? Should I be using the VJ8 extension do achieve this?
upload.php:
<script src="gallery.js"></script>
<?php
// A list of permitted file extensions
$allowed = array('png', 'jpg', 'gif','zip');
if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){
$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
if(!in_array(strtolower($extension), $allowed)){
echo '{"status":"error"}';
exit;
}
if(move_uploaded_file($_FILES['upl']['tmp_name'], 'img/main/'.$_FILES['upl']['name'])){
echo '{"status":"success"}';
echo "<script>refreshSortable(); alert('Hello from JS from Upload PHP!')</script>";
exit;
}
}
exit;
gallery.js:
$(function() {
$("#sortable-1").sortable({
update: function(event, ui) {
//alert("New position: " + ui.item.index());
alert($('#sortable-1').sortable('toArray'));
}
});
$(".btn").click(function (e) {
e.preventDefault();
var $li = $('<div class="gallery-item" id="01.jpg"><a href=""><img src=""></a><h4>Added Item<h4><div class="gallery-item-buttons"><input class="gallery-item-button" type="button"><input class="gallery-item-button" type="button"><input class="gallery-item-button" type="button"></div></div>');
$("#sortable-1").append($li);
$("#sortable-1").sortable('refresh');
});
});
function refreshSortable() {
$("#sortable-1").sortable('refresh');
}