我正在尝试使用AJAX创建一个依赖下拉列表。我成功地获得了所选的变量,但无法将其传递给PHP。这是我的代码:
行动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);
}
});
});
}
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");