• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CF session - can javascript interact with it?

LEGEND ,
Oct 30, 2012 Oct 30, 2012

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,

^_^

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 30, 2012 Oct 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?

Votes

Translate

Translate
LEGEND ,
Oct 30, 2012 Oct 30, 2012

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2012 Oct 30, 2012

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.)

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2012 Oct 30, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2012 Oct 30, 2012

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!

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2012 Oct 30, 2012

Copy link to clipboard

Copied

Depending on what is done to the form variables, you could use a very small iframe.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2012 Oct 30, 2012

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.  😕

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation