I'm trying to make a dependent drop down with AJAX. I managed to get the chosen variable but I can't pass it to the PHP. Here's my code:
action.js
window.onload = function($) {
jQuery("#brand").change(function() {
//get the selected value
var selectedValue = this.value;
//make the ajax call
jQuery.ajax({
type: 'POST',
data: {option : selectedValue},
success: function() {
console.log(selectedValue);
}
});
});
}
the php
$cars_post_id = $wpdb->get_col( "SELECT post_id FROM $wpdb->postmeta WHERE meta_value='".$_POST['option']"'" );
$separated = implode(",",$cars_post_id);
$car_model = $wpdb->get_col( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key='Model' AND post_id IN ($separated) GROUP BY meta_value ASC");