table department (department_id, name) table category (category_id, department_id, name)
I want to realize the idea that when changing a department in the drop-down list, all categories will change in accordance with the value of the department
This is 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 I can embed the code for the Ajax class in ajax.php file to return json
I do it as before but nothing happens 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 a class with PDO to implement this idea, help me plz
user272191
source
share