0

Drupal 7 中的 Ajax 自动完成文本字段在 Firfox 中有效,但在 IE 和 Chrome 中无效。出现以下错误:

发生 AJAX HTTP 错误。HTTP 结果代码:200 调试信息如下。
路径:http://localhost/drupal/en/example/autocomplete
状态文本: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, 
         );
...

Firefox 中的输出如下:在此处输入图像描述

4

1 回答 1

0

我发现了导致 AJAX 错误的原因!当我打开任何带有 utf8 编码的模块时,它会导致错误,当我将编码更改为 ANSI 或没有 BOM 的 utf8 时,一切正常。此编码问题仅在 Google chrome 中发生,在 Firefox 中所有编码都运行良好

于 2011-10-26T18:30:31.323 回答