An AJAX autocomplete textfield in Drupal 7 works in Firefox, 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

        $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:

enter image description here

  • I don't know but AJAX doesn't work at all in Chrome and IE. I tried AJAX Examples and got the same error=( – Alexey Oct 24 '11 at 16:39
  • Works just fine for me in IE8 and Chrome v14. Are you sure you are logged in and have the proper permissions on the other browsers? – Laxman13 Oct 25 '11 at 13:16
  • Yes, i'm sure. Very strange things are happening. If a turn off all my modules it works but if i keep more than one module on it gives the same error. I don't understand what's the relationship can bew between them – Alexey Oct 25 '11 at 13:20
  • I would see if you can find a pattern to which modules cause a problem. The code seems correct (assuming you have that form item in a function to display the form) and works on my somewhat basic D7 install, must be a localized issue – Laxman13 Oct 25 '11 at 13:25
  • If i turn on two modules newly created with the simple form it refuses to work in Chrome. But if i turn on one of them it works. I tried it also in a new Drupal 7 installation. – Alexey Oct 25 '11 at 13:45

I found out what causes AJAX error! When I turn on any module with UTF-8 encoding, it causes the error; when I change the encoding to ANSI or to UTF-8 without BOM, everything works. This encoding problem happened only in Google Chrome; in Firefox all encodings work well.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.