Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!