I am having an issue when using the jQuery $.getJSON ajax call, though the issue would occur if I used any jQuery ajax method. Here is an example of the code.
$.getJSON('cfcs/contact.cfc?method=method', registrantData, function(data){
// Data processing
});
Now the issue is, if I call my contact object in this manner, the initializer method for the object doesnt get called. So any of the dependencies I set up in the initializer are not available in the object methods. So if my contact object looks like below for example, calling the method function via Jquery ajax will fail.
..Contact.cfc
function init(){
injectedService = new injectedService()
}
function method(){
return injectedService.response();
}
Is there anyway round this, as I dont want to have to refactor my objects specifically when they need to be called via ajax?
Thanks
IMO, it looks like you’re going to have to create an proxy object to handle ajax calls if you need init() to fire off. So, ajax talks to proxy object. Proxy object creates cfc and passes arguments through and passes result back. That way, init will fire. This minimizes the change of all your objects to make this work.