2012-09-14 19:20
浏览 39


I want to set a session variable to 0 when any of a certain set of links are clicked. To do this I have put the following in my javascript file:

$(window).load(function () {
    $("#hdr li a").click(function () {
            type: "POST",
            url: "clear.php",
            data: "width=0"

(Ignore data: "width=0"... I don't use this data in clear.php. I put it there because I thought maybe I had to specify a data field.)

and in the file 'clear.php' I simply have:

<?php session_start();

$_SESSION['name'] = 0;


So, the idea is that when any of the links in #hdr li are clicked, the user should be taken to the page that the link points to, via clear.php, which sets the session variable to 0.

This works in some browsers (Firefox and Chrome) but not in others (e.g., Safari).

Is this the standard/correct way to implement what I want? Also, how does the browser know where to go after visiting clear.php? Somehow it works, but my first thought was that I should pass the final destination URL into clear.php, and then use "header" to move from clear.php to the final destination.

图片转代码服务由CSDN问答提供 功能建议

我想在点击任何一组链接时将会话变量设置为0。 为此,我将以下内容放在我的javascript文件中:

 $(“#hdr li a”)。  click(function(){
 $ .ajax({
 data:“width = 0”

(忽略数据:“width = 0”...我不在clear.php中使用这些数据。我把它放在那里 因为我想也许我必须指定一个数据字段。)


 &lt;?php session_start(); 
 $ _SESSION ['name'] = 0; 

所以, 想法是当点击#hdr li中的任何链接时,应该通过clear.php将用户带到链接所指向的页面,该会话变量将会话变量设置为0。


这是实现我想要的标准/正确方法吗? 另外,访问clear.php后,浏览器如何知道去哪里? 它以某种方式工作,但我的第一个想法是我应该将最终目标URL传递给clear.php,然后使用“header”从clear.php移动到最终目的地。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题