Skip to main content
WolfShade
Legend
October 30, 2012
Answered

CF session - can javascript interact with it?

  • October 30, 2012
  • 2 replies
  • 2137 views

Hello, everyone.

Just wondering if JavaScript can manipulate a CF session variable?

I'm submitting a form via jQuery .post() method.  Upon success or failure, I'd like to set a CF session variable (confirm or failure, respectively) and reload the page to display the message.  Can this be done via JavaScript?

Thank you,

^_^

    This topic has been closed for replies.
    Correct answer Dan_Bracuk

    session variables exist on the server.  javascript runs on the client.  To get javascript to talk to the server, you have to use ajax.

    Having said that, how are you determining success or failure?

    2 replies

    BKBK
    Community Expert
    Community Expert
    October 31, 2012

    WolfShade wrote:

    Just wondering if JavaScript can manipulate a CF session variable?

    If it could, then every user would be able to manipulate your application. If your application is a web store, for example, he will be able to change session.totalPrice from $1500.00 to $0.10.

    I'm submitting a form via jQuery .post() method.  Upon success or failure, I'd like to set a CF session variable (confirm or failure, respectively) and reload the page to display the message.  Can this be done via JavaScript?

    Yes. Infact, you've been doing that already! JQuery is Javascript. You could redesign the form page such that it is its own action page. That is, the form submits to its own page.

    The page checks for the existence of form variables. If there are none, the form is displayed(the page default). If there are, then the form must have been submitted, and so form processing like validation, confirmation, etc., is done.

    Dan_BracukCorrect answer
    Inspiring
    October 30, 2012

    session variables exist on the server.  javascript runs on the client.  To get javascript to talk to the server, you have to use ajax.

    Having said that, how are you determining success or failure?

    WolfShade
    WolfShadeAuthor
    Legend
    October 30, 2012

    About two minutes after I posted that question, I smacked myself in the forehead because I realized the AJaX angle. 

    Right now, because the data structure has yet to be determined, I'm just randomly generating SUCCESS and ERROR messages from the "processing" page, and trying to set the session variables.  Unfortunately, I'm apparently not doing something correct, as it is not setting either message, at the moment.  (Using CFSWITCH/CASE/DEFAULTCASE for the message setting.)

    ^_^

    Inspiring
    October 30, 2012

    Sounds like success and error are being generated by coldfusion.  Maybe you don't need js at all.