ASP - use JQuery to create session variable on click of a link


Is it possible to use JQuery to create session variables on the click link? I'm using classic ASP and i want to pass some variables to a page, but not through the query string.

Any suggestions?

Thank you
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom BeckCommented:
Just typing this on the fly, but it seems like you could use jQuery ajax for this. Something like:
          type: "POST", 
          url: "aPage.asp",
          data: { 
              'sessionname': 'sessionvalue'
          cache: false

Open in new window

Then in aPage.asp on the server side:
Session("whatever") = Request("sessionname")

Open in new window

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Using a session for something like this can be problematic because if something happens like the worker process resets then you loose your session.

Depending on why you want to not pass through the querystring, ajax may not be what you think because it is easy enough to see what data has been passed using the browser console.

What you can do is create a form and use jquery to submit the form on a click of a link.

<form id="MyForm" method="post" action="">
    <input name="firstname">
    <input name="lastname">
<a  id="submit_link">Click To Submit</a>
$( "#submit_link" ).click(function() {
  $( "#MyForm" ).submit();

Open in new window

Big MontyWeb Ninja at largeCommented:
i want to pass some variables to a page, but not through the query string.

if you're just wanting to pass data back to the server without using the query string, a simple POST method declared in your form is the easiest way to go:

<form id="frm" name="frm" action="page.asp" method="post"

if you're goal is to NOT refresh the page, then yes, you want to use ajax as others have pointed out.

briefly summarizing, ajax allows you to send data back to the server without having the page refresh (therefore not losing the page's state).

if you're just looking to store some basic data about the user, may be an option  (or
cookies set on the server side). as long as the data isn't sensitive, this would be a viable option as the majority of users allow cookies to be set nowaday (this wasn't always the option)

if you can give us some more info on what you're looking to do, it would help us determine the best course of action for you

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
garethtnashAuthor Commented:
Thank you All
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.