I have been working on this for some time now. I have a php file that has a div which reads a directory and loads the files in the directory into a dropdown. When the user selects from the file the file gets selected and teh operation is performed. However, the file name does not disappear from the dropdown until the page is refreshed. I have tried '.load' and it doesn't work. As in, the content of the div does not get updated.
My code is as follows: This is the PHP file:
<div id="mgA" class="form-group">
<label>Management Address:</label>
<?php
$path = "/licenses/ve/address/unused";
clearstatcache();
$files = array();
$handle = opendir($path);
echo '<select required id="mgmtAdd" class="form-control select2" style="width: 100%;">';
while ($file = readdir($handle)) {
if (substr($file,0,1) != ".") {
$files[]=$file;
}
echo "<option selected = 'selected' value='0'>Select</option>";
natsort($files); //sorting
foreach($files as $file){
echo "<option value ='$file'>$file</option>";
}
echo '</select>';
if (is_dir_empty($path)) {
echo "Max no of hosts already created";
}
function is_dir_empty($path) {
if (!is_readable($path)) return NULL;
return (count(scandir($path)) == 2);
}
closedir($handle);?>
This is the button which on click the div should reload all the contents again:
$( "#vServer").on( "click", function(e) {
e.preventDefault();
$("#mgA").load(virtualDialog);
alert("refreshed");
virtualDialog.dialog( "open" );
});
Please let me know if anyone has any idea, any help is appreciated! Thank you!