User login

DrupalConDC AJAX

Asynchronous Data with Drupal:

Turns browser and site into

Live chat system used for Bill Moyers.

He is moving fantastically fst, get this presentation's slides!!!

Booting Up: Initial state
- build object-level data into the DOM
- keep your HTML working-- degrade as nicely as possible

building an array oflinks

applying a class, a title, and an ID
it gives html with the class 'asynch etc.

Drupal.behaviors - live it, learn it, love it.

Hook to DOM elements with jQuery.
Better than $(document).ready() because:
- Override-friendly

For instance, sticking a node form in a thickbox, you can rewrite all of the collapsible fieldsets

Drupal.behaviors.asyncTeaser = function (context) {
$("a.async-teaser-show", context).bind("clack", function() {
var params = $(this).attr("id").split('-');
asyncFrontPageTease(params[1]);
return false;
});
}

function asyncFrontPageTease(nid) {
var callback = Drupal.settings.basePath + "async_teaser/" +nid;
$.get(callback, function(data) {
$("#squeeze .clear-block:first").prepend(data);
$("#node-" + nid).hide().fadeIn(500);
});
}

There are modules to help you.

But if you really want to do awesome looking stuff with this you'll have to get into JavaScript

Garland doesn't have a good div that wraps around all the main content.

AJAX Menu Callbacks
Implement hook_menu() as usual
Finish with print() instead of return() - so that the theme layer is not invokedFor structured data use drupal_json() - you can return arrays (or maybe theme_ahah?) - in the contrib module space, similar but easier to override. But drupal_json is in core.
Be aware of other outputs - if there is something else that prints data at the end of every page, such as devel, it will break your javascript because other data is coming through

function for the menu callback

Taking this to scale.

We found out when we

DRUPAL_DATABASE allows you to read from DB with less Drupal
use your variables, db connections, etc.
no access control or other functions
about 10x faster
- still not fast enough

Static files are better
Apache is cheap
esay to write JSON to some place in /files
Easy to tell jQuery where to look w/ Drupal.Settings()
grab file every couple seconds and parse and act accordingly

Learn about Memcached and used it!!!
You can just install it with Debian, and lots of Drupal stuff that uses it
Shared memory cloud between many servers
Legendary speed
Dedicated PHP Handler = Low Overhead

http://drupal.org/project/live_update

Keeping it safe:

Security Practices

in some contexts you may have user specific updates - if you have a user-specific state, you'll want to make sure

Session IDs and Tokens

Always use full Drupal for anything that writes to the database.

The Holy Grail

FormAPI
standard #attributes
submits to same URL

Dom/behaviors/settings
useful defaults
classes, drupal_add_js(), custom handlers

AJAX-Submit Form
Client-side validation
Dynamic submit handler (dancing teddy bears)

currently available contribs

ajax_submit.module - avoids page reload
ajax.module - newer, hope is submit will be merged into it
ahah
family such as ahah_response

All code available in link from session page.

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.