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

199
Visualizações
How can I pass the file when click submit button javascript?

I use ajax when I edit the product

$.get({
        url: '/admin/product/detail/' + productId,
        success: function(response) {
            editProductBody.innerHTML = `
                <form action="/admin/product/update/${response._id}?_method=PUT" method="POST">
                    <label for="">Product name<span style="color: red;">*</span></label> <br>
                    <input type="text" name="name" value="${response.name}"><br>
                    <label for="">Price<span style="color: red;">*</span></label> <br>
                    <input type="text" name="price" value="${response.price}"><br>
                    <label for="">Ảnh<span style="color: red;">*</span></label> <br>
                    <div class="row">
                        <div class="col-sm-9 ml-auto">
                            <img src="${response.photo[0]}"> <br>
                            <img src="${response.photo[1]}"> <br>
            </div>
                        <div class="col-sm-3 ml-auto"> 
                            <input type="file" class="form-control" name="image1" id="image1">
                            <input type="file" class="form-control" name="image2" id="image2">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <button id="btn-update-product" class="btn btn-primary">Update</button>
                    </div>
                </form>`

            for (let i = 0; i < categoryList.length; i++) {
                if (response.categoryId === categoryList[i].value) {
                    editProductBody.querySelector('select[name=categoryId').selectedIndex = i
                    break
                }
            }

            const submitBtn = document.querySelector('#btn-update-product')
            submitBtn.onclick = () => {
                editProductBody.querySelector('form').submit()
            }
        }
    })

When I req.body, it has image1, image2 but I want to transfer them as files to process with cloudinary. How can I fix it ?

over 4 years ago · Santiago Trujillo
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