views:

43

answers:

1

I'm working with a page in Coldfusion and I have instantiated an object on that page. Let's call the object myobject. I'm able to access all the methods of that object (such as myobject.getName()) on this page and all pages that are included as part of the page flow.

But now I load a page in via ajax, and I want to be able to reference that same object, but it seems I cannot do that. Further, on this ajax-loaded page I want to remote-call some methods that are a part of this object. I can remote-call the methods themselves, but again, if these methods invoke other object methods using, for instance, this.getName() then things don't work.

Is there a way to reference a previously-created object in an ajax-loaded page so that all this works seamlessly?

(I thought about doing this by encapsulating the object in a session variable, and this would probably work, but I'd prefer to find a solution that can work in a multi-server environment.)

I'm using Railo, which I believe in turn supports CF8 functionality. I'm not using any OO frameworks and really can't for this project.

+1  A: 

You can't reference an object instantiated on a page from ajax. The component you've instantiated is serverside. Your ajax is client side.

cfajaxproxy will create you a javascript proxy to your component so that you can call the methods on your component from javascript directly.

You could also use ajax functions to call your component from javascript as a remote object or webservice.

Stephen Moretti