因此,我試圖讓我的新窗格在Ubercart Checkout頁面上更新,只要有人選擇新的送貨選項。到目前爲止,我可以在選擇新的送貨選項後每次刷新頁面時都會發生這種情況。下一步是讓它工作在威盛AJAX。Drupal 7 AJAX通過hook_menu撥打電話
我的問題是,ajax命令不會從AJAX回調中觸發。該div沒有被更新。現在我只是有一些簡單的文字。之後,我將添加我需要的實際表單信息,這將是另一個問題。但是,我甚至無法讓這個測試案例起作用。
我正在爲Ubercart FedEx Module for Drupal提供一項新功能。我一直在研究這個問題一段時間無濟於事。我嘗試了很多不同的東西,但都沒有成功。
要非常清楚......我知道ajax調用正在發射。我甚至可以將成功附加到ajax $ .get調用並獲取控制檯輸出,並設置drupal變量。只有div替換代碼不起作用。這個難題的所有其他部分工作。
我得到ajax調用並返回到javascript。我甚至可以在JS中的ajax調用上附加成功函數,並在成功時獲取控制檯輸出。 JavaScript不是問題。
// 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
// THIS IS WHERE THE ERROR IS... the variable is set
// But the div content is 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 for shipping quote option without altering Ubercart Core.
// The $.get line makes the hook_menu call which in turn
// makes the call back to the above function that has the 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 Your 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 to allow customers to choose shipping date.'),
'process' => TRUE,
);
return $panes;
}
你試過用ahah –