• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sometimes Session is Lost in Ajax Call  RSS feed

 
Biswa R Nayak
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In all my pages, i am using same ajax interface to list the users in database when name is typed in a search input box. All Ajax works fine, except in few jsp pages. In those
pages when i type, ajax call gets the wrong session. Due to wrong session I can't get the session values and authentication in ajax fails. But in Main page, when i do page submit, session is there. I can get session objects upon page submit.

I have no clue how to fix this issue. Almost all my ajax call working perfect with session. I checked all ajax codes are exactly the same in all the pages. I am wandering why ajax in some pages are behaving different.

Regards,
Biswa.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never had anything like this happen. How is the wrong session being obtained?

Inspect the request/response and headers to find out when the wrong session info is being exchanged.
 
Biswa R Nayak
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your answer.

I am surprised myself with the behaviour of Ajax.

This is what i do to check session variable.

String strMyVariable = (String)request.getSession(false).getAttribute("myVariable");
if(strMyVariable == null) {
return "Invalid Session. Please login again.";
}
//continue processing..

This piece of code works well in all Ajax except few. I have no clue, because when i page submit the main page, I am checking the session using same code, and session is valid.

I printed the session Id in Ajax Call, it gives me different ID from the session ID in main page.

"Inspect the request/response and headers to find out when the wrong session info is being exchanged." I do not understand how i can do this?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need a tool such as HttpFOX.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My request that you change your display name to adhere to JavaRanch standards was not a suggestion. Valid display names are mandatory for participation on the Ranch. Please change your display name as instructed prior to your next post.

Be aware that accounts with invalid display names are disabled.
 
Biswa R Nayak
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, finally name is changed. I had to put m.i in my first name. dash was because my name is taken in java ranch.
-- thanks for your suggestion on tool. I will get back with result after sometimes.

biswa.
 
Biswa R Nayak
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what i got from main page using HTTPFox
JSESSIONID 1581B487E1E36491447142824236D286
JSESSIONID D86161A444D1B7C713D442325234D440

and in Ajax Call :
JSESSIONID D86161A444D1B7C713D442325234D440


when i print getId() in main page , i get 1581B487E1E36491447142824236D286
and when i print in Ajax , i get D86161A444D1B7C713D442325234D440

but in other ajax calls i get both the jsessionID

what is happening?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this happen in more than one browser?
 
Biswa R Nayak
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same behaviour in IE7, chrome and Firefox
 
J A Miller
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has there been a resolution to this issue? I'm having the same problem.

It looks like the browser isn't sending the session by cookie nor url rewriting, so the server assigns a new session ID. This only happens with the ajax request.
 
Biswa R Nayak
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, was resolved. If i remember, i found out the path for Ajax Call was wrong. Unfortunately, the browsers were giving me confusing error instead of saying "Path not found".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!