Hello all, I just went through converting an autoupdate explanation to Drupal 7, and I figure maybe another person can use it. For the sake of demonstration, I edited form example tutorial 7 in http://api.drupal.org/api/examples/form_example--form_example_tutorial.i...
Note: Original article for Drupal 6 with some explanation is here
http://toddkrokowski.blogspot.com/2008/06/auto-refresh-div-using-jquery-...
Here's what I did:
This assumes drupal is in the "site" folder.
Place this code in the function form_example_tutorial_7 which is in the file form_example_tutorial.inc
drupal_add_js('autoupdate.js', 'file');
$form["test"] = array(
'#markup' => "<div class=autorefresh>" .
"(Example Text That Should Be Replaced)" .
"</div>",
);
Create this script file and name it autoupdate.js
Place this file in the the site folder.
function autoupdate() {
//alert('autoupdate is running');
jQuery.ajax(
{
type: "POST",
url: "http://yoursite.com/site/examples/form_example/refresh",
cache: false,
success: function(data) {
var result = JSON.parse(data);
jQuery("div.autorefresh").fadeIn("slow").html(result['html']);
}
});
//alert('autoupdate is complete');
}
setInterval("autoupdate()", 2500);
Place this code in form_example.module file