I'm pulling my data from the database and then I want to load the pulled data with ajax but I am not able to do so.
Following is my code.
jQuery
code:
jQuery(document).ready(function () {
jQuery('#il').change(function () {
let il_id = jQuery(this).val();
jQuery.ajax({
type: "POST",
url: "../wp-content/themes/fancy-lab/ajax.php",
data: {il: il_id},
success: function (e) {
jQuery('#ilce').show();
jQuery('#ilce').html(e);
}
});
});
});
ajax.php
code:
global $wpdb;
$listele=$wpdb->get_results("Select * From wp_ilce where il_id={$_POST['il']}");
foreach ($listele as $val){
echo "<option value='$val->id'>".$val->ilce."</option>";
}
But I keep getting an error like this get_results returns null.
So where is the problem?