Can I access ColdBox handlers via ajax url? If so ...
# box-products
j
Can I access ColdBox handlers via ajax url? If so what would base url be?
d
Yes
j
I'm trying to figure out what the URL for my ajax call would be. Like the base url
d
depends on what you have implemented. do you have handler at the root handlers folder?
j
yes
d
and have you been able to hit that handler on the browser?
j
I do not know what the url would be, new to ColdBox. Trying to update pre-existing site at company with no prior knowledge of ColdBox
I have 20+ years of ColdFusion experience. Not so with ColdBox
d
I imagine you just started with Coldbox and haven't added any routes to /config/Router.cfc. So if you look at config/Router.cfc you will see
route(":handler/:action?").end()
This means your handler url is
{your_domain}/{name_of_your_handler_cfc}/{name_of_your_method_in_that_handler_cfc}
for example
<http://mysite.com/user/favorites|mysite.com/user/favorites>
which on the file system would be: /handlers/user.cfc (which has a method called "favorites")
@Jason Wilson this is half of it. the next thing would be to make sure your handler extends "coldbox.system.RestHandler". If you used the cli
coldbox create
to scaffold a rest application then your handler is already extending that restHandler. if not you can simply type that in your handler.
component extends="coldbox.system.RestHandler" {...}
then in your method/action simply return your data struct and the response will json.
💯 1
@Jason Wilson did you figure out how to request your coldbox handlers and get a json response?