Add code in your Application.cfc onSessionStart() method, that makes sure the default session variables exist right when the session starts.
You can also test for the session in onRequestStart() ,and call the onSessionStart() method if they don't exist. On Sun, Dec 23, 2012 at 8:51 PM, The Dude <[email protected]> wrote: > > I put a refresh tag below the script within conditions. It works, but > still not ideal. It seems there's no way to avoid the 2nd step either > redirect or form post. > > <cfif Not IsDefined('Session.Screensize.Width')> > <script type="text/javascript"> > var theData= "screenWidth=" + screen.width+ > "&screenHeight="+screen.height; > > $.ajax({ > type: "POST", > url: "/ajax.cfc?method=myMethod", > data: theData, > datatype: "json", > success: function(){} > }); > </script> > <meta http-equiv=refresh content="0;URL=test5.cfm"> > </cfif> > > Test page is: > > http://exelstudio.com/test5.cfm > > > > >>When I first loaded the page I received an error, after I refreshed > > the > > error went away. > > > > This method won't work either, because the Ajax function will be > > executed after the output of the page is already on client side. > > This is why you get an error at the first call. So you have to call > > the template two times so it can use the session variable. > > Furthermore, I'm not sure the Ajax function will use the same session > > as the calling program. > > > > > > A better way would be to use redirection. Example: > > <CFIF NOT isDefined("session.screenWidth")> > > > <CFIF NOT isDefined("url.sh")> > > > <SCRIPT> > > > window.location.href += "?sw=" + screen.width + "&sh=" + screen. > > height > > > </SCRIPT> > > > <CFELSE> > > > <CFSET session.screenWidth = url.sw> > > > <CFSET session.screenheight = url.sh> > > > </CFIF> > > </CFIF> > > <CFDUMP var="#session#"> > > > > You could also work out a POST method version using a FORM to transmit > > the values and the submit() function to redirect. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353659 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

