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
XMLHttpRequest returns null on Apache server but not lo

The following snippet of code computes the size of files located at url on my local system using Javascript

//returns file size given a URL
function getFileSize(url, key)
{
    var fileSize = '';
    var http = new XMLHttpRequest();
    http.open('HEAD', url, false);

    http.onreadystatechange = function() {
        if (this.readyState == this.DONE) {
            if (this.status == 200) {
                fileSize = this.getResponseHeader('content-length');

                //saves size in dictionary sizes
                sizes[key] = fileSize;
             }
        }
  };
  http.send();
}

When I deploy the code to my Apache server, however, this.getResponseHeader returns null, although the provided url correctly points to a file. I am considering different options for why this is the case (e.g., incorrect file permissions) but haven't found a solution yet. I also followed this link to change my server configuration to allow CORS but that didn't help. Any help would be greatly appreciated.

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I fixed the issue. In my .htaccess, I had added some filters to allow for HTML compression as explained here. However, this made my Apache server not include content-length in the html response (see here for more details). By getting rid of HTML compression in .htaccess, content-length is now included by the server.

about 4 years ago · Santiago Gelvez Relatório
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