Solved

Set Session Variable

Posted on 2010-09-02
8
1,249 Views
Last Modified: 2012-05-10
I have a form that has a button that on click makes an ajax call to a webservice that returns an entityobject.  How can i pass a value from the returned object to a session variable?  I am using jquery.ajax().
0
Comment
Question by:ikeyser
  • 4
  • 3
8 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 33592901
>How can i pass a value from the returned object to a session variable?

A new ajax call ? Or if possible, set it in the web service
0
 

Author Comment

by:ikeyser
ID: 33592915
Can you provide an example?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33592946
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:ikeyser
ID: 33592994
Thank you for the link but it doesn't provide an example of how I can pass data I get back from the ajax call.
0
 
LVL 14

Expert Comment

by:sam2912
ID: 33593066
You will have to make a second AJAX call to a server-side page to set the session variable.
0
 

Author Comment

by:ikeyser
ID: 33593089
Example please
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33593117
Example :


$(document).ready(function () {
        $.ajax({
            type: "POST",
            url: "WebService.asmx/HelloWorld",
            dataType: "html",
            data: "name=value",
            contentType: "html",
            success: function (data) {
                // do something with data here
                setSessionVar("HelloKey", "WorldValue");
            },
            error: function (data) {
                alert("error : " + data);
            }
        })
    });

    function setSessionVar(key, value) {
        $.ajax({
            type: "POST",
            url: "WebService.asmx/setSV",
            dataType: "html",
            data: encodeURIComponent(key) + "=" + encodeURIComponent(value),
            contentType: "html",
            success: function (data) {
                alert(data);
            },
            error: function (data) {
                alert("error : " + data);
            }
        })
    }

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 33593154
Thanks for the points!
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

777 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