Link to home
Start Free TrialLog in
Avatar of varimereweb
varimerewebFlag for United States of America

asked on

Assigning a dynamic application name in ColdFusion

Hello.  I am trying to assign a dynamic application name by passing a URL variable from the root directory into an index.cfm file in another directory.  For example, I'm on page index.cfm in the root directory and I want to pass the URL variable roomID with a value of 10 to rooms/index.cfm.  The rooms/ directory has an Application.cfc file that needs to be named with this URL variables' value.  Like this:

<cfset this.name = "Room_" & url.roomID>

It seems to be naming the Application file correctly.  When I do a <cfdump> on the this- and application- scopes, the CFC gets named, but nothing on the pages work.  I am using a lot of jQuery / AJAX features such as the $.ajax() function to retrieve text and output that text into <div> tags, so I'm not sure if that's what is causing the conflict or not.  Thanks!
Avatar of erikTsomik
erikTsomik
Flag of United States of America image

your url. should be passing correctly. what exactly does not work?
Avatar of varimereweb

ASKER

All of my jQuery functionality stops working when I try to assign a dynamic application name.  Hard-coding a static application name does not cause this issue.  For example, when the rooms/index.cfm page loads, this code is executed to refresh the div every minute:

$(document).ready(function() {
      // refresh messages on a regular basis:
      MessagesRefresh = function() {
            $.ajax({
                  type: "GET",
                  url: "Chat.cfc?method=fcnMessagesGet",
                  dataType: "json",
                  cache: false,
                  success: function(sMessages) {
                        $("div#messages").html(sMessages);
                        $("div#messages").attr({ scrollTop: $("div#messages").attr("scrollHeight") });
                  },
                  error: function(xhr) {
                        alert(xhr.status);
                  }
            });
            setTimeout("MessagesRefresh()", 1000);
      }
      MessagesRefresh();
});

This code is executed when the application name is static, but when I try to assign the application name with the passed in URL variable, the $.ajax() function returns an error status code of 500 (internal server error).
Avatar of _agx_
@varimereweb

It _might_ be possible, though definitely do NOT use URL variables here. That is unsafe and a bad idea.  But first, what are you trying to achieve here?  ie What benefits(s) do you need that you cannot get with a hard coded application name?


I am trying to write a mini-chat application.  The reason for the dynamic application name is so users in one room cannot view a conversation from users in another room.  I'm sure there are MUCH better ways of doing this, but this is the direction I am heading for now.
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
.. BTW: Though the application name can be dynamic, I am not at all sure it even _could_ work using URL variables.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, I was thinking it could be done a lot more simply using a db driven approach, or possibly the application scope. Store the users that should have access to various rooms. Then when a user tries to enter a room, validate against that list. Based on the results either allow or deny them entry to a room.