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

278
Visualizações
Why i cant send multiple file with different text using ajax or fetsh apiin javascript

this my code

articleForm.addEventListener('submit', (e)=>{
    e.preventDefault()
    var formData = new FormData() // create a new form data
    var article = []

    for (const element of editor_box.children){
        article.push(getElement(element))
    }

    article.push({'imagesNumber': JSON.stringify(allFiles.length)})
    formData.append('article', JSON.stringify(article))

    if (allFiles){
        for(var i=0; i<=allFiles.length-1; i++){
            formData.append(`file_${i}`, allFiles[i], allFiles[i].name)
        }
    }
    

    console.log(allFiles)

    // post the article to the server
    const endpoint = '/only-admin/article/upload'
    const req = new XMLHttpRequest()
    req.addEventListener('readystatechange', ()=>{
        if(req.status == 200 && req.readyState == 4){
            console.log(JSON.parse(req.responseText).res)
        }
    })
    req.open('POST', endpoint, true)
    req.send(formData)

    // fetch(endpoint, {
    //     method: 'POST',
    //     body: formData
    // })
    // .then(res=> res.json())
    // .then(text => console.log(text.res))

})

in this code i was trying to send multiple images with many json object to the server but the server return 308 error

the it allows to send one image with different json object but with there is many file or images it return that error;

about 4 years ago · Juan Pablo Isaza
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