I am trying to send data using ajax and getting response
This is my ajax code
jQuery( document ).ready(function() {
jQuery( "#district" ).change(function() {
var lvType = jQuery(this).val();
if(lvType == '')
{
alert('Please Enter District First');
return false;
}
jQuery.ajax({
url: '../wp-content/plugins/sevaapkedwar/menu-pages/search.php?q='+lvType,
type: 'get',
dataType: 'text/html',
success:function(data)
{
alert('ajax call finished successfully');
},
error: function (err) {
console.log(err);
}
});
});});
and my search.php
code is
global $wpdb;
$q = $_GET['q'];
$get_m = "select * from `sevaapkedwar_area` where `district_name` = '$q'";
$get_st_l = $wpdb->get_results($get_m);
//print_r($get_st_l);
$json = array();
foreach($get_st_l as $get_st_l){
$json[] = array(
'id' => $get_st_l->id,
'area' => $get_st_l->area_name
);
}
echo json_encode($json);
When I am running this code then in console the status of query is 200 OK with data [{"id":"8","area":"City1"}]
But I am unable to alert the message ajax call finished successfully
What I am missing