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

137
Visualizações
Using XMLHttpRequest upload files (Website is working on most browsers but doesn't work on iOS mobile phone)

I am using XMLHttpRequest to upload images to our server, and it works fine on (Firefox, Chrome, and Safari) when using a desktop and laptop.

When using iPhone to upload images, it failed without errors. The following is my upload function, and I am struggling with many hours please help. Thank you very much.

function ajaxFileUpload() 
 {

    var form = $('#imageform');
    files = form.find('[type="file"]');           

    if (files.length == 0) { 
       return;
    }


    var url = form.prop("action") 
    $('#loading').show();

    fileSelect = form.find('[type="file"]');
    
    var files = fileSelect[0].files;
    var fd = new FormData();
    for (var i = 0; i < files.length; i++) {
         var file = files[i];
         
         //remove deleted images from previous start
         var is_img_removed = false;
         for (j=0; j<imgList_removed.length; j++) {
            if (imgList_removed[j] == file.name) {
                is_img_removed = true;
                break;
            }
         }
         
         if (is_img_removed == true) {
            continue;
         }
         
         //remove deleted images from previous end
         fd.append('fileToUpload', file);
    }
    
    var xhr = new XMLHttpRequest();
    xhr.addEventListener('readystatechange', function(e) {
        if( this.readyState === 4 ) {
            form.find(":file").val("");
            alert('upload successfully');
        }
    });    
 
    xhr.open("POST", url, true);
    xhr.setRequestHeader('Accept-Encoding', 'multipart/form-data'); 
    
    xhr.send(fd);

    return false;
  }
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