【问题标题】:An Ajax Autocomplete Textfield In Drupal 7 doesn't work in ChromeDrupal 7 中的 Ajax 自动完成文本字段在 Chrome 中不起作用
【发布时间】:2011-10-22 13:19:22
【问题描述】:

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

发生 AJAX HTTP 错误。 HTTP 结果代码:200 调试信息如下。
路径:http://localhost/drupal/en/example/autocomplete
状态文本:好的
响应文本:{"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 中的输出如下:

【问题讨论】:

标签: ajax autocomplete drupal-7 http-error


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    • 1970-01-01
    • 2018-02-06
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 2019-07-13
    相关资源
    最近更新 更多