I cant't call a function inside jquery change event
when i use ajax directly inside change event it works fine but when I put ajax in a function and call the function inside change event id doesn't work
function get_child_cat() {
var parentID = $('#parent-cat').val();
$.ajax({
url: "/Ecom/parsers/prod-child-cat.php",
method: "POST",
data: {parentID: parentID},
success: function(data) {
$('#child-cat').html(data);
},
error: function() {
alert('something went wrong')
}
});
}
$('#parent-cat').on('change', function() {
get_child_cat();
});
I want to know how to make the function work inside the change event. Thank you