I have an autocomplete search box on the site I am working with currently. The autocomplete works fine as I type text in the box. However when I interrupt the autocomplete process by pressing the search button a javascript alert pops up with the message "An HTTP error 0 occurred".

There is a function to cancel the autocomplete request. Wouldn't it be possible to cancel the autocomplete request when the form is submitted?

Comments

mcsolas’s picture

+1. Having same issue running the same version.

Searches are not giving me much info yet. there are a few references to this in the drupal 5 issue bin... but doesn't seem to be any answers in there... still searching.

anoopjohn’s picture

If somebody could give me a pointer as to how to do this I can put some effort into fixing this error.

eikes’s picture

I had the same problem, and I really don't see how that alert is helpful to the normal user, so I just removed the alert:

opened misc/autocomplete.js and put two forward slashes before line 285 (Drupal 6.14), like this:

  // alert(Drupal.ahahError(xmlhttp, db.uri));

In HEAD it's a little further down, 292: http://drupalcode.org/viewvc/drupal/drupal/misc/autocomplete.js?view=markup

Beware though, when developing new autocomplete callbacks you will not be told anymore if you get 404s or the likes. As an alternative you can log it to the js-console:

console.log(Drupal.ahahError(xmlhttp, db.uri));

I think it would be best though if there was a way to log this to the drupal watchdog table and not use the javascript "alert", because it blocks the whole user experience. Obviously this would require making another AJAX request, but that would be ok, if we weren't waiting for an answer. so maybe http://drupal.org/project/jserrorlog should be ported to D6 and changed accordingly. Then maybe even overwrite the whole alert message:

window.alert = jsErrorLogger.onError;

Also I don't see how it is an error at all, when I type faster than the request is made, it's really terrible to keep me from doing that by throwing this ugly alert window on my screen.

I could go on... but you're basically set if you just remove the alert line.

Fabianx’s picture

Version: 6.14 » 6.16
Issue tags: +ahah

Hi,

The bug ist still there in 6.16. I also changed alert to console.log.

I think this should be fixed as that is really annoying to the user.

Best Wishes,

Fabian (LionsAd)

mcsolas’s picture

Yeah, I still have this pop up on occasion.. especially on the mac using firefox. Still not sure how to resolve this in any effective manner.

alienzed’s picture

see #3 for solution

you need to comment out that line in both misc/autocomplete.js AND sites/all/modules/finder/modules/finder-autocomplete.js

hefox’s picture

There is no need to modify core for this; javascript functions are overrideable.

Create or add to a js function to something that'd run after autocomplete, like in your theme layer

Add

/**
 * Performs a cached and delayed search
 */
if (Drupal.ACDB) {
  Drupal.ACDB.prototype.search = function (searchString) {
    var db = this;
    this.searchString = searchString;

    // See if this key has been searched for before
    if (this.cache[searchString]) {
      return this.owner.found(this.cache[searchString]);
    }

    // Initiate delayed search
    if (this.timer) {
      clearTimeout(this.timer);
    }
    this.timer = setTimeout(function() {
      db.owner.setStatus('begin');

      // Ajax GET request for autocompletion
      $.ajax({
        type: "GET",
        url: db.uri +'/'+ Drupal.encodeURIComponent(searchString),
        dataType: 'json',
        success: function (matches) {
          if (typeof matches['status'] == 'undefined' || matches['status'] != 0) {
            db.cache[searchString] = matches;
            // Verify if these are still the matches the user wants to see
            if (db.searchString == searchString) {
              db.owner.found(matches);
            }
            db.owner.setStatus('found');
          }
        }
      });
    }, this.delay);
  };
}

However, I agree that this error is only really useful for the developer.

edit: Updating code snippit

wanjee’s picture

Version: 6.16 » 6.x-dev

Hi,

Same error for me and I can repeat it easily.

I have a custom autocomplete callback that is used by a form element, add some delay in this callback if the autocomplete result appears too fast. Using Firefox, Safari or Chrome I get the error as soon as I submit the field by pressing enter before the autocomplete suggestion appears (while the blue working indicator is spinning in the field).
I think the error is logical but the alert is far too violent for lambda users.

I will apply solution of #7 but it would be great to get a more silent error in further releases, at least for user with less privileges.

Thanks,

Wanjee

vasike’s picture

subscribe

FiNeX’s picture

subscribe

Chi’s picture

subscribe

BigMike’s picture

subscribed

crifi’s picture

This problem is maybe caused by a wrong configuration of $base_url and should be prevented by inserting a warning message to the requirements system. Therefore I created a new issue #1046682: Install/Update process fails if $base_url is set to a wrong URL. Please close this bug as a duplicate, if this solves your issue. Thanks!

Jztinfinity’s picture

Issue tags: +autocomplete

I had a similar experience and here's the solution I hit.

So I had modified my autocomplete to add an autocomplete_select callback per - http://drupal.org/node/365241
I then added a callback to an autocomplete input that caused form.submit

Two issues:
1. based on the patch used (and rightfully given possible utility) the 'autocomplete_select' event fires onsubmit, which means adding a submit to the callback created an infinite loop. While jquery.one should have fixed the issue, for some reason it didn't, and so I went with a different approach, I attached to the form a class "submitting" and then added the condition that it not submit if that class was present on the form. Problem solved, but now the form wouldn't submit based on autocomplete.js' code for Drupal.autocompleteSubmit.

2. to solve the Drupal.autocompleteSubmit issue I ran $("#autocomplete").remove() before submitting, which solved the problem nicely.

For some reason and I'm still not sure why, the confluence of these two issues caused the "HTTP error 0 occurred" alert, and apparently fixing those issues caused it to be fixed. My theory? Because I'm removing out $("#autocomplete") it's killing off any possible new autocomplete attempts, which helps to avoid autocomplete interruption via form submit.

I hope this helps, although I'm not sure it will.

My 2 cents on Drupal.ahahError, Drupal should have a mechanism for switching on and off a "dev" variable which is accessible via js (directly through dynamic js, or alternatively via a body class, a meta tag, etc.). Thus one could then enable behavior of javascript useful for debugging but that should not be seen in production.

AdrianB’s picture

Thanks to crifi in #13. I had $base_url set to www.example.com but was using the site without www (only example.com), when I changed to www.example.com in my browser the error went away.

blaiz’s picture

Subscribe

extrem94’s picture

Subscribe

Naiya’s picture

Subscribe

for now i have added

if(Drupal.ahahError(xmlhttp, db.uri).indexOf("An HTTP error 0 occurred.") == -1) {
			alert(Drupal.ahahError(xmlhttp, db.uri));
		}

in autocomplete.js

Greetings

nod_’s picture

nod_’s picture

Status: Active » Closed (duplicate)

see above