Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda