php - Drupal 7 AJAX Call via hook_menu -
so, trying new pane on ubercart checkout page update whenever chooses new shipping option. far can occur every time refresh page after choosing new shipping option. next step working via ajax.
my problem ajax commands not firing ajax callback. div not being updated. right have simple text. later, add actual form information need, whole other issue. however, can't test case work.
i working on new feature ubercart fedex module drupal. have been working on time no avail. have tried many different things, none work.
to clear... know ajax call firing. can attach success ajax $.get call , console output , drupal variable set. div replace code not working. other pieces puzzle work.
i ajax call , return javascript. can attach success function on ajax call in js , console output on success. javascript not issue.
// implements hook_menu() function uc_fedex_menu() { $items = array(); $items['uc_fedex_jquery_callback/%'] = array( 'title' => 'my custom callback', 'description' => 'listing of blogs.', 'page callback' => 'uc_fedex_calendar_jquery_callback', 'page arguments' => array(1), 'access arguments' => array('access content'), 'access callback' => true, 'type' => menu_callback, ); return $items; } // ajax callback: updates calendar // error is... variable set // div content never replaced. function uc_fedex_calendar_jquery_callback($argument) { variable_set('uc_fedex_shipment_type',$argument); $commands[] = ajax_command_replace('#fromdate', "works"); return array('#type' => 'ajax', '#commands' => $commands); } // actual ui of calendar pane function uc_fedex_uc_checkout_pane_shipdate($op, $order, $form = null, &$form_state = null) { switch ($op) { case 'view': // check shipping quote option without altering ubercart core. // $.get line makes hook_menu call in turn // makes call above function has issue drupal_add_js(" jquery(function ($) { $(document).ready(function() { last = 'o'; setinterval(function() { $('#quote input:radio:checked').each(function() { if($(this).val() != last){ last = $(this).val() $.get('https://www.fdanconia.com/uc_fedex_jquery_callback/'+ $(this).val()); } }); }, 500); }); });", 'inline'); $contents['calendar'] = array( '#type' => 'textfield', '#title' => t('choose estimated arrival date'), '#default_value' => date('m/j/y',$response[1]), '#prefix' => '<div id="fromdate">', '#suffix' => '</div>', ); return array('description' => $description, 'contents' => $contents); } } // implements hook_uc_checkout_pane(). function uc_fedex_uc_checkout_pane() { $panes['calendar'] = array( 'callback' => 'uc_fedex_uc_checkout_pane_shipdate', 'title' => t('shipping calendar'), 'desc' => t('a calendar allow customers choose shipping date.'), 'process' => true, ); return $panes; }
a note js, jquery( function same_func(){} ) equivalent of $(document).ready( function same_func() {} )
so outer jquery() calls binds function document ready. function fires @ document ready, , bind function document ready, triggered.
most of time in drupal variable $ left unattached have explicitly create method(function) passes in jquery $.
(function($){ $ available in here })(jquery); think of the above as: (function)(variables) function takes variable $ .. or can think of this: function test ($) { $(jquery magic).etc()' } test(jquery);
.. except function test, , function call included on 'same' line.
check firebug/console see if $.get being called.
another debug use php's error_log('message') in uc_fedex_calendar_jquery_callback() , watch apache error.log.
Comments
Post a Comment