ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Drupal 7 Advanced AJAX
Tips and Tricks
Summary
? Non-form related AJAX
? Responding to an AJAX request
? Bind AJAX behavior to a simple link
? In more than one way
? Modify this behavior via javascript
? Modify the AJAX response via javascript
? Use a custom response command
? Perform AJAX on non-traditional events like a
timer.
We are skipping #ajax
? This is the basic usage
? Plenty of examples in examples.module
? Too tied to the form id and cache
Responding to an AJAX request
Drupal¡¯s AJAX Commands
? http://api.drupal.org/api/drupal/includes--ajax.inc/group/ajax_commands/7
Simplest Example
? <a href="/aajax-example/simple/nojs"
id="aajax-example-1" class="use-ajax">Simple
example</a>
? l(t('Simple example'), 'aajax-
example/simple/nojs', array('attributes' =>
array('id' => 'aajax-example-1', 'class' => 'use-
ajax')))
Second verse, same as the first
<a href="/aajax-example/simple/nojs" id="aajax-
example-2" class=¡°aajax-example use-ajax">Simple
example 2</a>
Setting up the AJAX event
? Use Drupal¡¯s behavior
? Bind to a DOM object
? Fill in the element_settings
? Register the Drupal.ajax object
Element Settings
Also:
? wrapper
Let¡¯s see this again
<a href="/aajax-example/simple/nojs" id="aajax-
example-2" class=¡°aajax-example use-ajax">Simple
example 2</a>
Manipulating the response
Custom AJAX Command
Javascript side
PHP Side
What about things that are not clicks?
Drupal 7 advanced ajax
Wrapping up
? This framework can integrate into strong
javascript applications.
? Server can be used for storage, rendering and
decision making.
? Client can be more interactive.
? Framework can add additional CSS and
javascript to page automatically.

More Related Content

Drupal 7 advanced ajax

  • 1. Drupal 7 Advanced AJAX Tips and Tricks
  • 2. Summary ? Non-form related AJAX ? Responding to an AJAX request ? Bind AJAX behavior to a simple link ? In more than one way ? Modify this behavior via javascript ? Modify the AJAX response via javascript ? Use a custom response command ? Perform AJAX on non-traditional events like a timer.
  • 3. We are skipping #ajax ? This is the basic usage ? Plenty of examples in examples.module ? Too tied to the form id and cache
  • 4. Responding to an AJAX request
  • 5. Drupal¡¯s AJAX Commands ? http://api.drupal.org/api/drupal/includes--ajax.inc/group/ajax_commands/7
  • 6. Simplest Example ? <a href="/aajax-example/simple/nojs" id="aajax-example-1" class="use-ajax">Simple example</a> ? l(t('Simple example'), 'aajax- example/simple/nojs', array('attributes' => array('id' => 'aajax-example-1', 'class' => 'use- ajax')))
  • 7. Second verse, same as the first <a href="/aajax-example/simple/nojs" id="aajax- example-2" class=¡°aajax-example use-ajax">Simple example 2</a>
  • 8. Setting up the AJAX event ? Use Drupal¡¯s behavior ? Bind to a DOM object ? Fill in the element_settings ? Register the Drupal.ajax object
  • 10. Let¡¯s see this again <a href="/aajax-example/simple/nojs" id="aajax- example-2" class=¡°aajax-example use-ajax">Simple example 2</a>
  • 13. What about things that are not clicks?
  • 15. Wrapping up ? This framework can integrate into strong javascript applications. ? Server can be used for storage, rendering and decision making. ? Client can be more interactive. ? Framework can add additional CSS and javascript to page automatically.