Views ajax "Drupal way"

WE HAVE MOVED!

Please visit our new Drupal Website at https://www.xenyo.com我們的新網頁設計公司網頁.

function modulename_crm_form($form , $form_state) {
  $form['notes'] = array (
    '#type' => 'textarea',
    '#title' => 'Notes',
  );
  $form['submit'] = array (
    '#type' => 'submit',
    '#value' => t('Add a note'),
    '#ajax' => array(
      'callback' => 'modulename_crm_ajaxcallback',
      'wrapper' => 'modulename-crm-form',
       'method' => 'replace',
    ),
  );
  return $form;
}
function modulename_crm_ajaxcallback($form, $form_state) {
  $values = $form_state['values'];
  /* do your logic here , example : save a node */
  $commands = array();
  $commands[] = ajax_command_invoke(NULL, 'crm_view_ajax', array($uid) );  //Drupal ajax framework api
  return array(
    '#type' => 'ajax',
    '#commands' => $commands
  );
}
 
/* js */
(function ($) {
  $.fn.crm_view_ajax = function() {
    alert('Do something here');
  }
})(jQuery);
Help Share this Article