Wie macht man Ajax im WordPress Custom Plugin?

Bildbeschreibung hier eingeben

Ich habe PHP-Datei für Country State City Dropdown, in dem ich bestimmte staatliche Liste nach bestimmten Länderauswahl und Städten Liste nach bestimmten Bundesstaat Auswahl. Jetzt möchte ich dasselbe Ergebnis durch WordPress Custom Plugin bekommen. Wie kann ich erreichen, bedeutet bestimmte Staaten Liste basierend auf bestimmten Länderauswahl in meinem WordPress-Plugin?

Ich habe versucht, ein benutzerdefiniertes Plugin in WordPress wie folgt zu erstellen: https://www.sitepoint.com/community/t/how-to-create-a-dropdown-menu-via-ajax-on-change-in -another-dropdown-menu / 112739/5 aber es zeigt nicht Staaten Dropdown-Liste. Ich weiß nicht, Fehler, PLZ Hilfe.

 admin_url( 'admin-ajax.php' ) ) ); } add_action('wp_enqueue_scripts', ajaxcontact_enqueuescripts); register_activation_hook( __FILE__, 'callback_plug' ); register_deactivation_hook( __FILE__, 'remove_plug' ); //callback function function callback_plug(){ global $wpdb; $table_country = $wpdb->prefix . "ajacs_drops"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_country) { $wpdb->query("CREATE TABLE $table_name ( entry_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, country_name VARCHAR(200) NOT NULL, state_name VARCHAR(200) NOT NULL )"); for($i=0;$iquery("INSERT INTO $table_country(country_name) VALUES('".$countries[$i]."')");} } /*$table_state = $wpdb->prefix . "ajacs_state"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { $wpdb->query("CREATE TABLE $table_name ( state_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, country_ID INT NOT NULL, state_name VARCHAR(200) NOT NULL )"); $wpdb->query("INSERT INTO $table_country(country_name,state_name) VALUES('1','".$state."')"); } else { } $table_city = $wpdb->prefix . "ajacs_city"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { $wpdb->query("CREATE TABLE $table_name ( city_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, state_ID INT NOT NULL, city_name VARCHAR(200) NOT NULL )"); } else { }*/ } function remove_plug() { global $wpdb; $table_name = $wpdb->prefix."ajacs_drops"; $wpdb->query("DROP TABLE IF EXISTS $table_name"); } if(is_admin()) { add_action('admin_menu', 'client_form_f1'); function client_form_f1() { add_menu_page('ajax','ajax Data','administrator','ajacs','client_form_fetch'); //add_submenu_page('case_studies','Display Clients','Display Clients','manage_options','case_slug','client_one_html_page'); } } function client_form_fetch() { $countries = array("India","america"); $all = array("India"=>array("Gujarat","Madhya Pradesh","Rajasthan")); ?> 
Select Country"; <?php for($i=0;$i <option value="">
//alert('Hii'); function state(){ $.ajax ({ type: 'POST', url: ajaxcontactajax.ajaxurl, data: { action:'fetch_state()', country:$('#country').val(), }, success:function(res) { $('#state').html(res); }, });} prefix."ajacs_state"; //$sel_state_data = $wpdb->get_results("SELECT * FROM $table_name WHERE country_ID = '".$_POST['country']."'"); $send = ""; $send .="Select State"; for($i=0;$i<count($all);$i++) { if($all[i] == $_POST['country']) { for($j=0;$j<count($all[$i]);$j++) { $send .= "".$all[$i][$j].""; }} } $send .= " "; return $send; } add_action( 'wp_ajax_nopriv_ajaxcontact_send_mail', 'fetch_state' ); add_action( 'wp_ajax_ajaxcontact_send_mail', 'fetch_state' ); /*function fetch_city() { global $wpdb; $table_name = $wpdb->prefix."ajacs_city"; $sel_state_data = $wpdb->get_results("SELECT * FROM $table_name WHERE state_ID = '".$_POST['state']."'"); $send = ""; $send .="Select Country"; foreach($sel_state_data as $sel) { $send .= "city_ID.">".$sel->city_name.""; } $send .= " "; return $send; }*/ /*function get_city($sid) { ?> $.ajax ({ type: 'POST', url: ajaxcontactajax.ajaxurl, data: { action:'fetch_city()', country:, }, success:function(res) { $('#city').html(res); }, });

Solutions Collecting From Web of "Wie macht man Ajax im WordPress Custom Plugin?"