From: "Fred Jones" <fredthejonester@gmail.com>
To: support@drupal.org
Sent: Wednesday, October 23, 2013 4:22:17 AM
Subject: Re: [support] AJAX

This is actually what Colorbox already does. Probably that's all you need:

https://drupal.org/project/colorbox
I'll investigate this, because even if it doesn't work for the current project, it will definitely work for the Photo Album part.  I oversimplified the description of what I was displaying to avoid misdirecting the conversation away for the aspect of AJAX.  I doubt that colorbox will work for the true content which is a PDF.  A picture is static, but a PDF needs controls like download and scroll bars.


If not, Google for "drupal ajax" and you will find the third result in
Google is an EXAMPLE of how to do it in Drupal, right on the Drupal
API site:

https://api.drupal.org/api/examples/ajax_example!ajax_example.module/group/ajax_example/7
This would be some of the MANY articles I've read.  They do not explain the questions I have.  I am sure there will come a day when I can read this and completely understand it but right now it does not explain things usefully. I've read it many times and I have not been able to produce anything useful, which is why I am asking questions.


> More specifically, how does 'class="use-ajax" ' do this magic?  I have to
> assume there is an onClick event handler hiding somewhere above me in the
> DOM looking for the class "use-ajax".  Where is this event listener
> attached? How does it become attached?  Where is the source, so I can see
> both the event handler and the attachment?

To understand the basics of Ajax if you prefer to do it yourself,
start with a tutorial. Here's one I found on Google:

http://www.w3schools.com/php/php_ajax_intro.asp
I understand the basics of AJAX, and I've used it before.  What I DON'T understand is how to use AJAX withing the confines of Drupal, which is not an AJAX question, but a Drupal question.



> Finally, how do I register my callback function which will operate on the
> returned JSON, which is a complicated question because I need an example of
> what I need to write, where I need to put it, and how I tell Drupal that it
> is there.

Google for "register ajax callback" and the first result is:

http://api.jquery.com/ajaxComplete/
This is a jQuery call, which is fine, but I have found no Drupal documentation that says to make this call.  So, this is also not illustrative.



I appreciate that you tried to help, but I still have many questions.  I did get a pointer from another source that sent me to http://www.interactivejunky.com/tutorial/ajax-commands-drupal-7 which has allowed me to create a minimal working example from which I can increase my understanding through brute force experimentation and intrusive debugging.  My recommendation to anybody following the path I am on is to read this.

Chris.