Hi! I'm currently migrating an app from Lucee to ...
# cfml-general
j
Hi! I'm currently migrating an app from Lucee to Adobe Coldfusion 2018 and I'm working through all of the errors I've generated because of that 😅 An error that I'm having a particularly difficult time with is that I have some javascript code that sends an ajax request:
await $.ajax(
{
type : "POST",
url : "./includes/ajaxColdfusion/formEditor/publishUnpublish.cfc?method=publish",
data : JSON.stringify(sendData),
dataType : "json",
cache : false
}
)
The javascript console keeps returning the following error: jquery-3.6.1.min.js:2 POST http://localhost:9001/includes/ajaxColdfusion/formEditor/publishUnpublish.cfc?method=publish 400 (Bad Request) I've attached screenshots of the error as well. I understand the change that I've made from Lucee to Adobe ColdFusion 2018 must mean that there's something to do with the way cfcs are accessed remotely, as I can access this method and successfully get an output if I copy and paste the address into my browser. I'm curious if anyone knows what mistake I might be making or if there's a resource for devs trying to take a Lucee app and make it work for Adobe ColdFusion.
1
r
Do you have debugging enabled? If so, you'll need to disable it for the request. Also, does the Response pane show any additional information?
1
m
Can you hit the CFC endpoint in any way? Like, is it listed and available in the REST playground?
j
I'm not sure where to check if I have debugging enabled, but I do have environment set to development in my server's .env file.
This is what the response pane looks like:
I am able to hit the CFC endpoint by copying and pasting the link (http://localhost:9001/includes/ajaxColdfusion/formEditor/publishUnpublish.cfc?method=publish) into my browser's web address bar. However, the response it prints to the screen is an error because I'm not supplying the correct variables to the method by hitting the method that way.
m
Edit the function to just dump a text response. Comment out the other stuff. Start from simplicity, remove variables, etc. Once you can hit it and get the plain return, start adding back everything else.
j
So I took everything out but the function definitions of the CFC. I then just made the publish method return a struct. The publish method look like this:
Accessing it directly in the browser looks like this:
Accessing it remotely via the jquery ajax function looks like this in the javascript console, still:
r
What if you add returnFormat="JSON" to your function declaration? Like so
remote struct function publish() returnFormat="JSON"
The only other thing I can think of is an Application.cfc interfering with the request.
1
j
Okay! So it looks like that works.
I added returnFormat="JSON" to my function definition and I also added another argument to my jquery ajax call:
The contentType must be "application/json"
The successful response in the console:
👍🏻 1
👍 1
Thank you for the help!