【问题标题】:PHP cannot unset session variablePHP 无法取消设置会话变量
【发布时间】:2014-04-03 07:48:32
【问题描述】:

我无法取消设置用于搜索过滤器的会话变量。单击 domain.com/index.php?filter=clear 时没有任何反应,并且过滤器未清除。

我正在混合使用 php 和 JS 来使用 AJAX 更新表格

PHP:

/**
 * Clears the current filter
 */
function clear()
{
    unset($_SESSION['filter']);

    // Clear current page
    unset($_SESSION['arctic_page']);
}

}

JS:

clear: function()
{
    // Show loading image
    new Element('img', { src: '/images/loading.gif' }).setStyle('float', 'right').injectTop(Issues.container.getElement('h2'));

    // Create AJAX request
    new Ajax('index.php',
    {
        method: 'get',
        data: 'ajax=true&filter=clear',
        update: 'issue_list',
        onComplete: Issues.initialise
    }).request();
}

【问题讨论】:

  • 你在顶部添加了session_start(); 吗?
  • 是的,session_start();包含在我的 init.php 中(在加载过滤器之前)
  • 您实际上在主页上获得的会话 ID 与您在 ajax 请求上获得的会话 ID 相同吗?
  • 你在哪里调用clear()函数?
  • 是的,我返回的是相同的会话 ID。并且 clear() 函数位于超链接 domain.com/index.php?filter=clear

标签: javascript php ajax session session-variables


【解决方案1】:

它看起来像原型 JS,对吗?我已经有一段时间了,但我认为这是正确的语法:

new Ajax.Request('index.php',
{
    method: 'get',
    data: 'ajax=true&filter=clear',
    update: 'issue_list',
    onComplete: Issues.initialise
});

【讨论】:

  • 这似乎也不起作用。我实际上使用的是北极虫追踪器的略微修改版本
猜你喜欢
  • 2016-10-01
  • 2013-02-17
  • 2011-11-13
  • 1970-01-01
  • 2017-08-09
  • 2023-01-23
  • 2015-03-03
  • 2013-01-17
相关资源
最近更新 更多