Ajax.Autocompleter is not a constructor
Using script.aculous to create some cool effects on your website? Ever get this error message?
Ajax.Autocompleter is not a constructor
All of the results I found on Google suggested that the solution to the problem was to make sure that you were including controls.js (which is where the autocompletion stuff lives in script.aculous). If you checked and double checked that you have controls.js (or that you’re including scriptaculous.js which itself includes controls.js), then your problem could be that you included prototype.js twice. Example:
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="scriptaculous.js"></script>
<script>
function createAC() {
new Ajax.Autocompleter('mytextbox', 'myautocomplete',
'autocomplete/url', {});
}
</script>
<input type="text" id="mytextbox" name="username" value="" />
<div id="myautocomplete" class="autocomplete"></div>
<a href="#" onclick="createAC(); return false;">start autocomplete</a>
<script type="text/javascript" src="prototype.js"></script>
Why? Prototype defines a class ‘Ajax’:
var Ajax = {
getTransport: function() {
...
and then Script.aculous extends that class:
Ajax.Autocompleter = Class.create();
Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.prototype), {
...
So including prototype.js a second time blows away the class defined by Script.aculous. Really easy to fix, but if you’re working on a large team, make sure that prototype.js is only included once on every page.
11 Comments