Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

212
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda