Solved

Set Session Variable

Posted on 2010-09-02
8
1,240 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
Comment Utility
>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
Comment Utility
Can you provide an example?
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
0
 

Author Comment

by:ikeyser
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 14

Expert Comment

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

Author Comment

by:ikeyser
Comment Utility
Example please
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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
Comment Utility
Thanks for the points!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

763 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

11 Experts available now in Live!

Get 1:1 Help Now