Remote Session Exisit?

Posted on 2012-09-21
Last Modified: 2012-09-21
If I invoke a remote CFC/CFM from JQuery using AJAX ($.get), do the session variables still exisit for the caller?  It's a little hard to test.

Question by:hefterr
    LVL 39

    Assisted Solution

    Yes they do.  The session is kept alive through cookies which the cfc/m has available even through ajax
    LVL 51

    Accepted Solution

    Yes, there shouldn't be a difference. You're still calling the page from a browser, so the normal rules for sessions still apply.

         >  It's a little hard to test.

    Create a cfc that returns info about the session (ie id and some variable) then call it from a test page.

    Test Component:
       <cffunction name="testSession" access="remote" returnType="string">
                <cfargument name="arg" type="string" />
                <cfif not structKeyExists(session, "userName")>
                      <cfset session.userName = "bob"& randRange(1, 1000)>
                <cfreturn "Session: "& session.sessionid &" userName="& session.userName &" called at "& now() />

    Test Page:
    <script src="" type="text/javascript">/script>
    <script type="text/javascript">
          function test() {
                $.get('http://localhost/path/someComponent.cfc?method=testSession&arg='+ Math.random(), function(data) {
    <div class="result"></div>
    <a href="javascript:test()">Test</a>
    LVL 51

    Expert Comment

    {Sigh} ... EE really needs ajax notifications...
    LVL 1

    Author Comment

    {Sigh} ... EE really needs ajax notifications...

    What do you mean by this?
    LVL 1

    Author Closing Comment

    LVL 51

    Expert Comment

    @hefterr - Nothing to do with your question, just 2 responses colliding ie saying the same thing at the same time... EE should have some sort of ajax notification to let you know new comments were posted while you were composing an answer. So you can edit/cancel your response if someone else already said some of the same things. Currently you don't know unless you refresh the page .. and you have to do it in a new tab/window so you don't lose the answer you're composing. Seems like a perfect job for ajax.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
    PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video discusses moving either the default database or any database to a new volume.

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now