我需要使用一个依赖下拉列表。我正在使用Drupal7。我的代码如下:
$selected = isset($form_state['values']['channels']) ? $form_state['values']['channels'] : key($options);
$form['channels']=array(
'#type'=>'select',
'#title'=>'Discussion Channel',
'#options'=>$options,
'#default_value' => $selected,
'#required'=>true,
'#ajax' => array(
'callback' => 'ajax_update_entries_callback',
'wrapper' => 'entries-dropdown',
),
);
// Dependent dropdown list
$form['entries']=array(
'#type'=>'select',
'#title'=>'Related Discussions',
'#prefix' => '<div id="entries-dropdown">',
'#suffix' => '</div>',
'#options'=>_ajax_load_entries($selected),
'#required'=>true,
'#default_value' => isset($form_state['values']['entries']) ? $form_state['values']['entries'] : '',
);
function ajax_update_entries_callback($form, &$form_state) {
return $form['entries'];
}
function _ajax_load_entries($selected=''){
$options = array();
$dbh = new kbDatabase;
$newentry = new NewEntry($dbh);
$entries = $newentry->channelwiseEntries($selected);
foreach($entries as $row){
$options[$row->nodeID] = $row->title;
}
return $options;
}
页面完美加载,并且选择的默认值很好,但是当我从主下拉列表中选择另一个项目时,出现以下AJAX错误:
An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /system/ajax
StatusText: OK
ResponseText:`
[{"command":"settings","settings": {"basePath":"/","pathPrefix":"","ajaxPageState":{"theme":"bartik","theme_token":"VtqPSjlZrRndHfl7cP6IZgoVOWf566jywm8Yg8jYhkI"},"overlay":{"paths":{"admin":"node/*/edit\nnode/*/delete\nnode/*/revisions\nnode/*/revisions/*/revert\nnode/*/revisions/*/delete\nnode/add\nnode/add/*\noverlay/dismiss-message\nuser/*/shortcuts\nadmin\nadmin/*\nbatch\ntaxonomy/term/*/edit\nuser/*/cancel\nuser/*/edit\nuser/*/edit/*","non_admin":"admin/structure/block/demo/*\nadmin/reports/status/php"},"pathPrefixes":[],"ajaxCallback":"overlay-ajax"}},"merge":true},{"command":"insert","method":null,"selector":null,"data":"\u003Cdiv id=\u0022entries-dropdown\u0022\u003E\u003Cdiv class=\u0022form-item form-type-select form-item-entries\u0022\u003E\n \u003Clabel for=\u0022edit-entries--2\u0022\u003ERelated Discussions \u003Cspan class=\u0022form-required\u0022 title=\u0022This field is required.\u0022\u003E*\u003C/span\u003E\u003C/label\u003E\n \u003Cselect id=\u0022edit-entries--2\u0022 name=\u0022entries\u0022 class=\u0022form-select required error\u0022\u003E\u003Coption value=\u002218\u0022\u003EAdvancing decentralised data governance\u003C/option\u003E\u003Coption value=\u002246\u0022\u003EHow to balance between citizen-centric NGI and business models based on the data economy\u003C/option\u003E\u003Coption value=\u002279\u0022\u003EDencentralisation of Control\u003C/option\u003E\u003Coption value=\u002290\u0022\u003E\u003C/option\u003E\u003Coption value=\u002292\u0022\u003EFixing asymmetry in data governance and Adam Smith\u0026#039;s invisible hand\u003C/option\u003E\u003C/select\u003E\n\u003C/div\u003E\n\u003C/div\u003E","settings":null},{"command":"insert","method":"prepend","selector":null,"data":"\u003Cdiv class=\u0022messages error\u0022\u003E\n\u003Ch2 class=\u0022element-invisible\u0022\u003EError message\u003C/h2\u003E\nAn illegal choice has been detected. Please contact the site administrator.\u003C/div\u003E\n","settings":null}]`
请指导我如何摆脱它?我没有使用任何打印方法来打印任何种类的杂项信息。我没有使用JQuery_Update模块。