[support] jQuery/JSON automated page refresh, check box update and variable set

Jensen Somers foss at jsomers.eu
Mon Aug 25 08:57:33 UTC 2008


Hello,

I am developing a module (Drupal 6.4) which shows a list of online 
servers. The list is refreshed each X seconds. I used the book "Learning 
Drupal 6 Module Development" and inside I found the perfect trick. I 
created an empty page which contains 2 blocks.

Block A: contains the server list and using JSON/jQuery it gets 
refreshed each X seconds.

Block B: contains a form with 3 check boxes.

So far I am only using block A and everything works as expected. The 
server list is shown and gets refreshed each X seconds. The goal is to 
allow the check boxes in Block B to control which type of online servers 
are listed. For this I needed something like on-toggle -> set variable. 
I don't want to use any real submit form stuff but the status the check 
box should change and I should be able to perform a variable_set().

Thanks to someone on the Drupal IRC channels I got the following piece 
of code:

$('input[@type=checkbox]').click(function() {
   $.ajax({
     type:'POST',
     data:{val:$(this).attr('checked')},
     url: 'path_to_a_drupal_menu_item',
     dataType: "json",
     success:function(json) {
       alert(json.result);
     }
   });
});

I am not sure however how this works.  I assume I need to put it in my 
module's .js file and it will call the 'path_to_drupal_menu_item' but 
how is the result processed? Is it passed as an argument and can I fetch 
it and perform a variable_set() or does it simply update the page itself 
and changes the html element 'checked' of the check box?

Any help and/or pointers towards a correct solution are greatly appreciated.

- Jensen


More information about the support mailing list