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

275
Vistas
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 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