i am trying to make a dependend picklist set in a wordpress plugin. Within the plugin i have a javascript with the following method
$('#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);
}
});
});
the get-contacts.php file looks like
<?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>';
//}
}
?>
i have tried a lot. I know the URL is good, and the page is being called. I have comment everything out except the echo line, i see that the pulldoen is being updated with that echo line.
BUt i want to use the $wpdb method to get rows from the database. But the moment i uncomment the line $result = $wpdb->get_results ( "SELECT * FROM $listitems" ); it does not work anymore. I get an empty errormessage. the alert(xhr.responseText); is being called but is empty. If i comment the $wpdb line out, then is works again.
I have really no clue what i am missing. The $wpdb I use very heavily and works like a charm except in the example here.
Any ideas? BR Marzel