Reputation: 4069
I have a ColdFusion function that checks if a record exists in a table, and if it does it returns data for the row found. However, if the record does not exist, I would like to have it make a call to a JavaScript function that I've written and use the value that is returned from the JS function to continue processing in the CF function. I know that CF is written in Java, so I'm hopeful that there is someway to perform this task.
Basically, from CF page, the steps would be...
Any ideas? Thank you for any help!
Upvotes: 2
Views: 3675
Reputation: 29870
You need to understand that CF and JS do not exist in the same environment, and cannot interact with each other like that: http://blog.adamcameron.me/2012/10/the-coldfusion-requestresponse-process.html.
Your JS can make a remote call to CF, but CF cannot initiate a call to JS based on its processing, because whilst CF is processing, everything is still on the server, so JS is not part of the recipe.
The best you can do is to have the CF code write out JS code which is then sent to the browser, which is then executed when the browser comes to execute JS during page rendering.
But that really doesn't fit with what you are wanting to do here.
Anything you do has to fit into the request/response life cycle.
You can do this:
functions.cfc
functions.cfc
's method call can only process and then return something to the JS that fired the request in 1.functions.cfc
to continue processing.What you can't do is have the step at 2 both call back to JS and continue processing and then return something else to JS later on. Each request can only have one response. So you might have to use multiple requests.
Upvotes: 8
Reputation: 4069
Was over complicating things trying to use javascript for the ajax call. Just switched over to using cfhttp and all is working as needed. DeserializeJSON method of CF works great to parse the json object returned from the Google API.
Upvotes: 2