我试图在wordpress插件中设置一个依赖的选取列表。在插件中,我有一个javascript,使用以下方法
$(\'#am_organisation\').change(function(){
var val = $(this).val();
$.ajax({
type: \'POST\',
url: \'/wp-content/plugins/harriecrm/admin/get-contacts.php\',
data:\'organisation_id=\'+val,
success: function(data){
$("#am_contact").html(data);
//$("#loader").hide();
},
error: function(xhr, status, error) {
alert(xhr.responseText);
}
});
});
theget-contacts.php 文件看起来像 <?php
global $wpdb;
global $xx;
if(isset($_POST[\'organisation_id\'])){
$id = $_POST[\'organisation_id\'];
$listitems = $wpdb->prefix . \'am_contacts\';
$result = $wpdb->get_results ( "SELECT * FROM $listitems" );
//foreach ( $result as $print ) {
// echo \'<option value="Maak een keuze">Maak een keuzesss-\' . $id . \'</option>\';
//}
//if($wpdb->query($sql)){
// $resp->uf_error = $wpdb->print_error();
// alert($resp);
//};
// $result = $wpdb->get_results ($strsql);
//foreach ($result as $value) {
// echo \' <option value=\'.$value->id.\' \'.$selected.\'>\'.$value->am_firstname. ", ".$value->am_firstname. \'</option> \';
echo \'<option value="Maak een keuze">Maak een keuzesss-\' . $id . \'</option>\';
//}
}
?>
我试了很多。我知道URL很好,并且正在调用该页面。除了回音线,我已经对所有内容进行了注释,我看到pulldoen正在使用回音线进行更新。但我想使用$wpdb方法从数据库中获取行。但当我取消注释行$result=$wpdb->;get\\u结果(“SELECT*FROM$listitems”);它不再工作了。我收到一条空的错误消息。警报(xhr.responseText);正在调用,但为空。如果我将$wpdb行注释掉,那么is再次起作用。
我真的不知道我错过了什么。除了这里的示例之外,我使用的$wpdb非常多,工作起来很有魅力。
有什么想法吗?BR马泽尔