JavaScript

Drupal 7 Ajax Custom Module Example

This is an example  module that  shows some ideas of what you can do  drupal  ajax in a custom module  I will make a custom auto suggest box with the form api , and has ajax call back with the menu call back , stick that in a custom block, then do some jquery stuff to make it all work.

PRE COMMENT :
I Know I  am breaking some best practices  - but that  fine this is just an example ...
if you understand what I am doing below then you are smart enough to  understand what to do next.

Ajax Simple Auto Suggest - Jquery

So you want to make an auto suggest  and you don’t want to use a jquery plug in that is fine
here is an example of how to do it  with Jquery .load() !

You need 2 files for testing :

1) index.html , or index.php – front end
2) return.php  - returned results

3) Loader Gif ()

Code for  your front end file:

Drupal7 work with jquery in a module

I agree that there are better ways to do this but some times you need just a few functions or need php to help create a jquery function inside a module 

	$output ='<script>
	(function($) {
Drupal.behaviors.myBehavior = {
  attach: function (context, settings) {
    //code starts
 $(document).ready(function() {
	 alert("hello");
 });
 
    //code ends
  }
};
})(jQuery);
	</script>';