redoc01
redoc01

Reputation: 2325

Persisting Session State via multiple request using jQuery $.ajax()

just been trying to recieve the session value from multiple jquery ajax requests on the same domain name. i think i understand that each request is kind of a virtual browser request so the session is mutally exclusive to each request, but there must be a way some how, has anyone solved this. Basically this is what im trying to do:

I have tries using type: GET and POST but still no luck.

Can anyone help please, Thanks?

First request - Stores the product id in a session

$.ajax({

    url: 'http://localhost/websitetest/test.aspx?storeproduct=' + productid,
    type: 'GET',  
    async: true,
    success: function(data) {
    }

});

Second Request - From the callback variable "data" recieves the product id from the session

$.ajax({

    url: 'http://localhost/websitetest/test.aspx,
    type: 'GET',  
    async: true,
    success: function(data) {
          var productID = data;
    }
});

Upvotes: 0

Views: 1538

Answers (1)

user284291
user284291

Reputation:

There is no question to send ajax request while accessing Session variable from asp page.

Simply you can do is :

<%
String session_var = Session("name_of_session_variable");
%>

Even if you still want to try Ajax, I think you will need to print the session variable in test.aspx file using Response.Write(), which will automatically return the content.

Please check this for further reference.

Please correct me as well if I am wrong.

Thank you.

Upvotes: 1

Related Questions