Solved

How to write value to Session object

Posted on 2002-05-19
8
266 Views
Last Modified: 2012-08-14
Hi,

I have the following code:

function doRemember()
{
  var htmlCode = iView.document.body.innerHTML;
  alert(htmlCode); // Data are being displayed OK!
  Session("htmlCode") = htmlCode;
  alert(Session("htmlCode")); // Does not seem to work!
}

Session("htmlCode") does not get changed... What is wrong? How can I store some value in Session object?

Thanks in advance!
0
Comment
Question by:long8
  • 5
  • 2
8 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 7020749
you cannot update, delete or add Session variables from client-side script. This is so because the script executes only on the client and the server has no knowledge of the changes.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7020750
what you can do is pass the data back to the server so that it will be changed e.g. via the XMLHTTP Object
or write the changes to cookie on the client side and have your ASP Code read it e.g. Request.Cookies("user")("id")
0
 

Author Comment

by:long8
ID: 7020765
Ah, OK, but could you please tell me how can I pass data from client side to server? Cookies are not acceptable, because they can be turned off in browser.

Is submitting data to database only method?

I'm not very familiar with JS and Web programming at all..
Actually what I need is to pass some text (passing data via URL is not good - text may be rather large) entered by user on one page to another. May be you know a better way?

If you advise me, I'll accept your answer :)
0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 200 total points
ID: 7020783
I would presume that you are using IIS and ASP yes? Well, you may not realise it but for Sessions to work, the client browser must have cookies turned on =).

There is an easy way to update Sessions via the XMLHTTP Object but for which is MSIE Centric (IE5+) and the Web Server should have MSXML Installed (It probably has if you have MSIE5+).

client
======
<script language="javascript">
var oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
var oXML = new ActiveXObject("Microsoft.XMLDOM");
oXML.async = false;

function doRemember() {
 var htmlCode = iView.document.body.innerHTML;
 alert(htmlCode); // Data are being displayed OK!
 if (oXML.documentElement) {
  oXML.removeChild(oXML.documentElement);
 }
 oXML.appendChild(oXML.createElement("payload"));
 oXML.documentElement.appendChild(oXML.createCDATASection(htmlCode));
 oHTTP.open("POST","http://myserver.com/updateSession.asp",false);
 oHTTP.send(oXML);
 alert(oHTTP.responseText);
}
</script>

updateSession.asp
=================
<%@language="VBScript"%>
<%
 On Error Resume Next
 Dim oPayload, szValue
 Set oPayload = Server.CreateObject("Microsoft.XMLDOM")
 oPayload.async = False
 oPayload.load Request
 If oPayload.parseError.errorCode <> 0 Then
  'do nothing
 Else
  szValue = oPayload.documentElement.text
  Session("htmlCode") = szValue
 End If
 Set oPayload = Nothing
 Response.Write Session("htmlCode")
%>




0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 23

Expert Comment

by:b1xml2
ID: 7020784
This will allow the data to be passed back to the server discretely without needing a normal HTML form post or a complete page refresh.
0
 

Author Comment

by:long8
ID: 7021045
Wow! Thanks! I didn't try it yet - but it looks exactly what I needed. :)
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7021074
be sure to ask for any further assistance here if you need and if EE notification is dead, just holler at b1xml2@yahoo.com so that I can come here to this thread to answer your question. Thanks for the grade A =)
0
 

Expert Comment

by:vfwong
ID: 7675357
Do anybody know how to write value to session using JSP?
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now