Ich habe zwei Dropdowns Stadt und Postleitzahl in meinem Formular. Wenn eine Postleitzahl vom Benutzer ausgewählt wurde, möchte ich das Stadt-Dropdown auf die entsprechende Postleitzahl der Stadt w.r.t ändern. Ich versuche dies mit Ajax zu erreichen.Wählen Sie Wert wird nicht geändert mit jQuery und Ajax
jQuery-Code:
$(document).on('change','#zip_id', function(e){
e.preventDefault();
var zipID = jQuery(this).val();
if(zipID){
jQuery.ajax({
url: ajaxschoolajax.ajaxurl,
data: {'zip_id': zipID, 'action':'cityOptions_Process'},
type: 'POST',
success: function(data){
jQuery('#temp').html(data);
},
error: function (exception) {
console.log("Error");
console.log(exception);
}
});
PHP Funktion
function cityOptions_Process() {
if(isset($_POST["zip_id"]) && !empty($_POST["zip_id"])){
$selectedZip = $_POST["zip_id"];
global $wpdb;
$sql = "SELECT `city_id` FROM `wp_gj73yj2g8h_hills_zipcodes` WHERE zip_id = '$selectedZip'";
$data = $wpdb->get_row($sql);
$output = $data->city_id;
echo $output;
die();
}
}
add_action('wp_ajax_nopriv_cityOptions_Process', 'cityOptions_Process');
add_action('wp_ajax_cityOptions_Process', 'cityOptions_Process');
Unangemessen response Daten Ajax zeigt in Ajax Fehler Funktion
entfernen, was Wert der Variablen 'city' in Erfolgsfunktion? Teilen Sie auch HTML von Select-Element. –
Ich erhalte als undefined – Himani
Hier ist der Link: http://accessrealtytampa.com/hillsborough-county-homes-school – Himani