weixin_33720452 2013-07-14 13:21 采纳率: 0%
浏览 27

Drupal 7 Ajax和会话

I have created a .module file which includes a form and an ajax call back. Here is a simple code of the .module file:

function form_registration_form($form, &$form_state) {
      $form['registration']['email'] = array(
        '#type'      => 'textfield',
        '#required'  => TRUE,
        '#size'      => 44,
        '#maxlength' => '80',
        '#attributes'=> array('placeholder' => 'Email','data-email'=>'','data-min-chars'=>'5'),
      );
      $form['registration']['password'] = array(
        '#type'      => 'password',
        '#required'  => TRUE,
        '#size'      => 44,
        '#maxlength' => '80',
        '#attributes'=> array('placeholder' => 'Password'),
      );
      $form['registration']['submit'] = array(
        '#value'     => 'SIGN IN',
        '#type'      => 'submit',
        '#submit'    => array('form_registration_handler'),
        );
      return $form;
}
and in the function form_registration_handler I create a session (name it test).
Here is the ajax menu call back function:

function mymodule_menu() {

    $items['ajax/innerAction'] = array(
        'title' => 'Browser Inner Action',
        'page callback' => 'innerActionCallBack',
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,
    );

    return $items;
}

function innerActionCallBack() {
    header('Access-Control-Allow-Origin: *');
    drupal_session_start();
    print session_id();
}

This function is used on my page.tpl.php file to create an ajax to server. The problem here is when I call the ajax, the session id is different when I refresh the browser and I can not retreive the Session test that I created earlier. Do you know what is happening here. Any helps are really appreciated.

  • 写回答

1条回答 默认 最新

  • weixin_33704591 2013-07-22 05:22
    关注

    Ok so I have figured out the answer. I have to login the user into Drupal first so that Drupal can retrieve the correct sessionID.

    评论

报告相同问题?

悬赏问题

  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题