# Session Problem with Ajax Call

**URL:** <https://www.ruby-forum.com/t/session-problem-with-ajax-call/107205>\
**Category:** Rails\
**Created:** [June 19, 2007, 5:57am UTC](https://www.ruby-forum.com/t/session-problem-with-ajax-call/107205 "2007-06-19T05:57:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![selva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@selva](https://www.ruby-forum.com/u/selva)\
**Post date:** [June 19, 2007, 5:57am UTC](https://www.ruby-forum.com/t/session-problem-with-ajax-call/107205/1 "2007-06-19T05:57:10Z")

</div>

Hai,

```
I am totally new to Ajax. I am trying to use ajax in my project. Its

```

working fine, I am getting problem while session time expires. If  
session expires means i am redirecting to login page.Onclick i am  
calling on ajax function. It will goto controller and it will check the  
session if session expires then it has to goto login page.

```
 On ajax call i am updating the div. If session expires means its

```

calling the login page, but it updating that div.

Regards  
Selvaraj

---

<div class="post-metadata">

**Author:** ![selva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@selva](https://www.ruby-forum.com/u/selva)\
**Post date:** [June 19, 2007, 10:25am UTC](https://www.ruby-forum.com/t/session-problem-with-ajax-call/107205/2 "2007-06-19T10:25:10Z")

</div>

any idea???

selva wrote:

> Hai,
> 
> ```
> I am totally new to Ajax. I am trying to use ajax in my project. Its
> 
> ```
> 
> working fine, I am getting problem while session time expires. If  
> session expires means i am redirecting to login page.Onclick i am  
> calling on ajax function. It will goto controller and it will check the  
> session if session expires then it has to goto login page.
> 
> ```
> On ajax call i am updating the div. If session expires means its
> 
> ```
> 
> calling the login page, but it updating that div.
> 
> Regards  
> Selvaraj

---

<div class="post-metadata">

**Author:** ![selva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@selva](https://www.ruby-forum.com/u/selva)\
**Post date:** [June 22, 2007, 9:24am UTC](https://www.ruby-forum.com/t/session-problem-with-ajax-call/107205/3 "2007-06-22T09:24:41Z")

</div>

selva wrote:

> Hai,
> 
> ```
> I am totally new to Ajax. I am trying to use ajax in my project. Its
> 
> ```
> 
> working fine, I am getting problem while session time expires. If  
> session expires means i am redirecting to login page.Onclick i am  
> calling on ajax function. It will goto controller and it will check the  
> session if session expires then it has to goto login page.

Your “session\_expired” filter should check if this is an xhr request, if  
yes a redirection is needed you’ll have to send back javascript  
redirection snippet:

return unless session expired?  
flash[:notice] = “Your session expired”  
if request.xhr?  
render :update do |page|  
page.redirect\_to login\_path  
end  
else  
redirect\_to login\_path  
end  
false

best,  
zsombor

–  
Company - [http://primalgrasp.com](http://primalgrasp.com)  
Thoughts - [http://deezsombor.blogspot.com](http://deezsombor.blogspot.com)
