Copy link to clipboard
Copied
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,
^_^
1 Correct answer
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?
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.)
^_^
Copy link to clipboard
Copied
Sounds like success and error are being generated by coldfusion. Maybe you don't need js at all.
Copy link to clipboard
Copied
The form is being submit via AJaX, so JS is integral unless someone can suggest another way of submitting the data without refreshing the page. I finally got it to start working, just not exactly as I would have liked. (shrug) It will be sufficient, for now.
Thanks, guys!
^_^
Copy link to clipboard
Copied
Depending on what is done to the form variables, you could use a very small iframe.
Copy link to clipboard
Copied
I suggested to a co-worker about using an iframe on another project, a month or so ago.. iframes are despised, hated, and just not done in this shop. At all. 😕
^_^
Copy link to clipboard
Copied
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.

