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

150
Views
No se puede recuperar texto del servidor xampp porque XMLHttprequest.readystate siempre devuelve 'indefinido'

Traté de acceder a un archivo .txt almacenado en la carpeta htdocs de mi instalación de xampp usando solo Javascript y no PHP. Solo tengo la intención de usar ajax para procesar un archivo de texto almacenado en el servidor. Este es mi código javascript para hacer una solicitud asíncrona:

 (function(global){ var ajaxUtils = {}; function getRequestObject(){ if(window.XMLHttpRequest){ return (new XMLHttpRequest()); } else{ global.alert('Ajax is not supported!'); return(null); } } ajaxUtils.sendGetRequest = function(requestUrl, responseHandler){ var request = getRequestObject(); request.onreadystatechange = function(){ handleResponse(request, responseHandler); }; request.open("GET",requestUrl,true); request.send(null); } function handleResponse(request, responseHandler){ console.log(request.readystate + " " + request.status); if((request.readystate == 4) && (request.status == 200)){ responseHandler(request); } } global.$ajaxUtils = ajaxUtils; })(window);

Así es como pasé parámetros a ajaxUtils.sendGetRequest():

 document.addEventListener("DOMContentLoaded", function(event){ document.querySelector("button").addEventListener('click', function(){ this.textContent='Said it!'; $ajaxUtils.sendGetRequest('http://localhost/ajax/file.txt',function(request){ var name = request.responseText; var message = "<h2>Hello " + name + '!</h2>'; document.getElementById('content').innerHTML=message; }); }); });

El código no funcionó y esto es lo que obtuve en la consola: request.readystate siempre devuelve 'indefinido'

La propiedad 'readystate' de XMLHttprequest puede tener valores 0,1,2,3 o 4, pero aquí siempre devuelve 'indefinido'. ¿Alguien sabe por qué sucedió esto?

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!