When defining an Ajax handler, you should consider defining both for logged in and non logged in users. You can do so by using:
add_action('wp_ajax_my_handler', 'callback_function');
add_action('wp_ajax_nopriv_my_handler', 'callback_function');
Now, as for your question. We can turn this code into a REST endpoint, if you are interested, which is faster and easier to set up. Let’s start by defining a route.
add_action( 'rest_api_init', function () {
register_rest_route( 'karts', '/ins_get_membershiptypes_from_country/', array(
'methods' => 'GET',
'callback' => 'ins_get_membershiptypes_from_country_callback'
) );
});
At this point, we can run our quest by accessing:
www.example.com/wp-json/karts/ins_get_membershiptypes_from_country/
Now the Ajax call. Use this to localize your script, and pass the site URL:
wp_localize_script( 'member-front-script','ins_membership_ajax', array(
'ajax_url' => site_url()
));
So, we can access the path in our Ajax call:
$("#member_country").change(function() {
var country = $(this).val();
alert(country);
var ajax_url_mtypes = ins_membership_ajax.ajax_url + '/kartsins_get_membershiptypes_from_country';
alert(ajax_url_mtypes);
jQuery.ajax({
url:ajax_url_mtypes,
method:'GET',
data : { country : country},
dataType: 'json',
success:function(response) {
//var resp = $.trim(response);
alert(response);
//$("#ins-member-profile-select-state").html(resp);
}
});
Not that I have defined a JSON data type for the call. This way, you will get a Json response by default.