Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
Coldfusion inserting db record and downloading file using Ajax

Im trying to create a button that when clicked inserts a record into the database and then downloads a file. I'm trying to do this via Ajax, the file download works but it isn't inserting the record in the db.

Trigger

<button type="button" class="btn btn-primary" onClick="downloadFile1()">Download</button>

Script

function downloadFile1(){
var file1 = 'https://example.com/files/myfile.zip'; 

    $.ajax({
        TYPE: "POST",
        URL: "components.cfc?method=DownloadFile1",
        data: {fileId : 3},
        success: function() {
                window.location = file1;
        }
    });
}   

</script>

Components.cfc

<cfcomponent output="false">
<cffunction name="DownloadFile1" access="remote" returntype="string"> 
 <cfcontent type="text/html">
    <CFQUERY NAME="i">
        INSERT into t_terms
        (bid, fildid)
        VALUES
        (
        <cfqueryparam value="#session.busid#" cfsqltype="CF_SQL_INTEGER">,
        <cfqueryparam value="#url.fileID#" cfsqltype="CF_SQL_INTEGER">)
    </CFQUERY>
</cffunction>

Could someone point out where I am going wrong?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Like Jack said above, since you're doing a POST and not a GET, instead of looking in the URL scope, try looking in the "FORM" scope.

 <cfqueryparam value="#form.fileID#" cfsqltype="CF_SQL_INTEGER">

Or, you could just look for "fileID". If it is being passed in, your query will work. If not, it will throw an error.

<cfqueryparam value="#fileID#" cfsqltype="CF_SQL_INTEGER">
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!