Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Set Session Variable

Posted on 2010-09-02
8
Medium Priority
?
1,267 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 83

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 83

Expert Comment

by:leakim971
ID: 33592946
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 83

Accepted Solution

by:
leakim971 earned 2000 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 83

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

810 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