希望这对你有帮助+如果你明白的话,我就给你1英镑。
第一步//您的动态下拉字段
<select id="customers">
<option value="None Selected"></option>
<?PHP
$customers = $wpdb->get_results("SELECT * FROM _cif_customers_table;");
foreach ($customers as $customer) {
echo \'<option value="\'.$customer->id.\'">\'.$customer->company.\'</option>\';
}
?>
</select>
第二步://使用ajax从customer表中获取数据后,将显示客户数据
<div class="col-lg-6">
<fieldset style="text-align:left;padding: 5px; border: 1px solid rgb(128,128,128);">
<legend>Sold To</legend>
<textarea id="text_area" style="resize:none;" rows="4" cols="50"></textarea>
</fieldset>
</div>
第三步://您的ajax使用on change函数
<script>
$(\'#customers\').on(\'change\', function() {
//get the value
var customer_id = $(this).val();
/// run the ajax
$.ajax({
url: \'<?php echo admin_url(\'admin-ajax.php\'); ?>\', //ajax url
type: \'post\',
data: { action: \'customer_data\', customer_id: customer_id }, // ajax parameters
success: function(data) {
$(\'#text_area\').html( data ); // fetch data show on textarea
}
});
}
});
</script>
//函数。php ajax
add_action(\'wp_ajax_customer_data\' , \'customer_data\'); //ajax parameter action
add_action(\'wp_ajax_nopriv_customer_data\',\'customer_data\');
function customer_data(){
$customer_id = $_POST[\'customer_id\']; //id
//fetch the customer data here .....Your QUERY
//and return the values.
die;
}