Tuesday, June 25, 2013

Calling a Drupal module function from jquery ajax.

You can call a module function from the jquery ajax function to perform some database related operations based on ajax.
To start, create a menu item using hook_menu

function mymodule_menu() {

 
$items = array();

  // Create a path to send our AJAX request to.
 
$items['mymodule_ajax'] = array(
   
'title' => 'menu title',
   
'page callback' => 'mymodule_ajax_function',   
   
'access arguments' => array('access example ajax'),
   
'type' => MENU_CALLBACK,
  );

  return
$items;
}

function
mymodule_ajax_function(){
// Here you can perform your database operations
   
$var = "testing";
    return
drupal_json($var);
}


And then add a js file to your module and paste the following code.

Drupal.behaviors.mymodule=function(context){

//click event
jQuery.ajax({
url: "mymodule_ajax",
                        type: "POST",
dataType: "json",
                        success:  function(data){
alert(data);
}
                      });

}


Cheers

Friday, April 12, 2013

Changing the admin password using drush of a drupal site.

Here is the drush command for changing the admin password for the drupal admin user.
drush upwd admin --password=your_new_password
The admin will be the username of the user with user id 1.