0

i cant seem to get my json data into a selection box. here my code for the dropdown.php

</head>

<script src="jquery.js"></script>
<script src="jquery.jCombo.js"></script>
<style type="text/css">
</style>

<?php
$directory = opendir("C:/xampp/htdocs/SE3S604CW3/xml");

$storeFilesIntoArray[] = "please select XML to load";

while (($fileName = readdir($directory)) !== false)
{
 $getLastFourDigitsOfFile = substr($fileName,-4); 

 if($getLastFourDigitsOfFile == ".xml")
 {
  #echo "filename is " . $fileName . "<br/>";
    $storeFilesIntoArray[] = $fileName;
 }
}
$json = json_encode($storeFilesIntoArray);
echo $json;
closedir($directory);

?>

</script>

<body>

</body>
</html>

which shows the following;

["please select XML to load","cd_catalog.xml"]

here on my main.php page when ive done this bit of code, nothing seems to be happening, am quite new to doing these callback functions.

<script src="jquery.js"></script>
<script src="jquery.jCombo.js"></script>
<style type="text/css">

</style>

<script type="text/javascript">

$(document).ready(function(){
    $.getJSON("dropdown.php", function(data){
        var select = $('#list1');
        if (select.prop){
            var options = select.prop('options');
        }
        else{
            var options = select.attr('options');
        }
        $('option', select).remove();
        $.each(data, function(key, value){
            options[options.length] = new Option(value['name'], value['id']);
        });

    });

});
</script>
<body>
<select name="list1" id="list1"></select><br><br>
</body>
</html>

hope someone can help me figure out where ive gone wrong :)

2
Contributors
1
Reply
4
Views
4 Years
Discussion Span
Last Post by LastMitch
0

hope someone can help me figure out where ive gone wrong :)

This issue you are having is not really related to PHP even though you post a few lines. This is more like a Ajax issue rather a php/mysql issue.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.