My problem is when I remove the prototype.js, my autosuggest script is working, when I put it back my ajax post request fail.
Any help would be appreciated. Thank you.
The problem is both jQuery and the Protoype libraires both make use of the $ variable, to avoid having issues like this jQuery has a built in method called noConflict which allows you to release the use of $ when using jQuery in your page. The only change you need to make apart from adding the noConflict declaration is move the jQuery <script> resource above the Protoype resource or the conflict will continue.
The jQuery.noConflict() declaration needs to go directly after your jQuery <script> element and before the Prototype element other it will still cause an error.
The jQuery.noConflict() declaration needs to go directly after your jQuery <script> element and before the Prototype element other it will still cause an error.
jQuery.noConflict()
(function(){
/*
* jQuery 1.2.6 - New Wave Javascript
*
* Copyright (c) 2008 John Resig (jquery.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* $Date: 2008-05-24 14:22:17 -0400 (Sat, 24 May 2008) $
* $Rev: 5685 $
*/
// Map over jQuery in case of overwrite
var _jQuery = window.jQuery,
// Map over the $ in case of overwrite
_$ = window.$;
var jQuery = window.jQuery = window.$ = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
};
// A simple way to check for HTML strings or ID strings
// (both of which we optimize for)
var quickExpr = /^[^<]*(<(.|\\s)+>)[^>]*$|^#(\\w+)$/,
// Is it a simple selector
isSimple = /^.[^:#\\[\\.]*$/,
// Will speed up references to undefined, and allows munging its name.
undefined;
jQuery must be loaded before he noConflict command can be issued.
From what I’m seeing up there, you are trying to run noConflict before the jQuery library., which just won’t work.
The noConflict command has to be issued only after the jQuery library has been loaded.