Drupal 7 中的 Ajax 自动完成文本字段在 Chrome 中不起作用
Drupal 7 中的 Ajax 自动完成文本字段适用于 Firfox,但不适用于 IE 和 Chrome。 出现以下错误:
发生 AJAX HTTP 错误。 HTTP 结果代码:200 调试信息如下。
路径: http://localhost/drupal/en/example/autocomplete
状态文本:确定
ResponseText: {"admin":"admin","alex":"alex","apple":"apple"}
function clubform_menu() {
$items['example/autocomplete'] = array(
'page callback' => '_module_name_autocomplete',
'access arguments' => array('access example autocomplete'),
'type' => MENU_CALLBACK
);
return $items;
}
function _module_name_autocomplete($string) {
$matches = array();
$return = db_query("SELECT name FROM users where lower(name) like '".$string."%' LIMIT 10");
// add matches to $matches
foreach ($return as $row) {
$matches[$row->name] = check_plain($row->name);
}
// return for JS
drupal_json_output($matches);
}
...
$form['editclub']['club_name'] = array(
'#title' => t(''),
'#type' => 'textfield',
'#description' => t(''),
'#autocomplete_path' => 'example/autocomplete',
'#weight' =>15,
'#size' => 30,
);
...
Firefox 中的输出如下:
An Ajax Autocomplete Textfield In Drupal 7 works in Firfox, but doesn't work in IE and Chrome.
The following error appears:
An AJAX HTTP error occured. HTTP Result Code: 200 Debugging information follows.
Path: http://localhost/drupal/en/example/autocomplete
StatusText: OK
ResponseText: {"admin":"admin","alex":"alex","apple":"apple"}
function clubform_menu() {
$items['example/autocomplete'] = array(
'page callback' => '_module_name_autocomplete',
'access arguments' => array('access example autocomplete'),
'type' => MENU_CALLBACK
);
return $items;
}
function _module_name_autocomplete($string) {
$matches = array();
$return = db_query("SELECT name FROM users where lower(name) like '".$string."%' LIMIT 10");
// add matches to $matches
foreach ($return as $row) {
$matches[$row->name] = check_plain($row->name);
}
// return for JS
drupal_json_output($matches);
}
...
$form['editclub']['club_name'] = array(
'#title' => t(''),
'#type' => 'textfield',
'#description' => t(''),
'#autocomplete_path' => 'example/autocomplete',
'#weight' =>15,
'#size' => 30,
);
...
The output in Firefox is the following:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了导致 AJAX 错误的原因!当我打开任何使用 utf8 编码的模块时,它会导致错误,当我将编码更改为 ANSI 或不带 BOM 的 utf8 时,一切正常。此编码问题仅发生在 Google chrome 中,在 Firefox 中所有编码都工作正常
I found out what causes AJAX error! When I turn on any module with utf8 incoding it causes the error, when i change the encoding to ANSI or to utf8 without BOM, everything works. This incoding problems happened only in Google chrome, in Firefox all encodings work well