0

当我使用管理员用户运行代码时,模块会返回它应该返回的内容。但是,当我使用普通用户运行它时,会出现 403 错误。该模块从 AJAX 调用返回数据。我已经尝试添加一个'访问回调'=>'user_access');exoticlang_chat_logger_menu()函数的行。我会很感激你可能有的任何指示。

谢谢您的帮助

AJAX 调用:

jQuery.ajax({
    type: 'POST',
    url: '/chatlog',
    success: exoticlangAjaxCompleted,
    data:'messageLog=' + privateMessageLogJson,
    dataType: 'json'
});

模块代码:

function exoticlang_chat_logger_init(){
drupal_add_js('misc/jquery.form.js');
drupal_add_library('system', 'drupal.ajax');
}

function exoticlang_chat_logger_permission() {
  return array(
    'Save chat data' => array(
      'title' => t('Save ExoticLang Chat Data'),
      'description' => t('Send private message on chat close')
    ),
  );
}

/**
 * Implementation of hook_menu().
 */

function exoticlang_chat_logger_menu() {
    $items = array();
    $items['chatlog'] = array(
    'type'             => MENU_CALLBACK,
    'page callback'    => 'exoticlang_chat_log_ajax',
    'access arguments' => 'Save chat data');
    //'access callback' => 'user_access');
    return $items;
}

function exoticlang_chat_logger_ajax(){
    $messageLog=stripslashes($_POST['messageLog']);

    $chatLog= 'Drupal has processed this. Message log is: '.$messageLog;
    $chatLog=str_replace('":"{[{','":[{',$chatLog);
    $chatLog=str_replace(',,',',',$chatLog);
    $chatLog=str_replace('"}"','"}',$chatLog);
    $chatLog=str_replace('"}]}"','"}]',$chatLog);

     echo json_encode(array('messageLog' => $chatLog));
//    echo $chatLog;

    echo print_r(privatemsg_new_thread(array(user_load(1)), 'The subject', 'The body text'));
    drupal_exit();
}
4

1 回答 1

2

access arguments需要是一个数组:

$items['chatlog'] = array(
  'type'             => MENU_CALLBACK,
  'page callback'    => 'exoticlang_chat_log_ajax',
  'access arguments' => array('Save chat data')
);
于 2012-08-29T21:37:20.513 回答