I am trying to delete image files, after populating data about the file in a modal.
My jQuery looks like this:
const deleteMedia = () => {
const url = '../../includes/delete-media.cfc?method=deleteMedia';
$(document).on('click', '.confirm-delete', () => {
const fileName = $('.modal-wrapper').find('.file-name').text();
$.ajax({
url,
type: 'POST',
data: 'fileName=' + fileName,
dataType: 'json',
success(data) {
console.log(data);
},
error(status) {
console.log(status.statusText);
}
});
return false;
});
};
export default deleteMedia;
And my Coldfusion file delete-media.cfc:
<cffunction name="deleteMedia" access="remote" returnType="any" returnformat="json">
<cfargument name="fileName" >
<cfset requestBody = toString( getHttpRequestData().content ) />
<!--- Double-check to make sure it's a JSON value. --->
<cfif isJSON( requestBody )>
<cfset VARIABLES.DeleteFileName = deserializeJSON( requestBody )>
<cffile
action = "delete"
file = "C:\pathToSite\img\#variables.DeleteFileName#"
>
<cfdump var="#variables.DeleteFileName#">
</cfif>
</cffunction>
This is sending fileName = fileName as data when I check in the Network panel, and returning a 200, although I cannot see contents of the cfdump.
I am OK with the FE, not so hot on CF, my guess is that my CF is overly complex but also not doing what I hope it would do. I did try and reference some stuff I wrote a while back, plus this:
How to use Ajax to pass Javascript variables to Coldfusion?
And this:
Passing and returning ColdFusion Structure via JQuery
Any ideas?