table department(department_id, name) table category(category_id, department_id, name)
I want to implement the idea that when i change department in drop down list, all categories will change according to the department value
It 's my jquery script
{literal}
<script type="text/javascript">
$(document).ready(function(){
$('#department').change( function() {
var departmentVal = $(this).val();
$("#category option").remove();
$.getJSON("ajax.php",{departmentId: $(this).val(), dataType: "json", ajax: 'true'},
function(j){
var options = '';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].category_id + '">' + j[i].name + '</option>';
}
$("#category").html(options);
})
});
});
</script>
{/literal}
I want to know how can i implenent code for class Ajax in file ajax.php to return json
I do it like it before but nothing happen b/c i dont use class
$category= array();
while($grab = $db->fetch_array($result)) {
$category[] = array('optionValue' => $grab['category_id'], 'optionDisplay' => $grab['name']);
}
echo json_encode($category);
Now i want to use class with PDO to implement this idea, help me plz