• Jobs
  • About Us
  • Jobs
    • Home
    • Jobs
    • Courses and challenges
  • Businesses
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

457
Views
¿Cómo acceder a los archivos usando la función de obtención de jQuery?

Estoy tratando de cargar archivos que el usuario selecciona en un elemento de selección múltiple. Un ejemplo mínimo sería algo como esto:

 <!doctype html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> </head> <body> <select name="file-select" id="file-select" multiple> <option>http://url.to.file/Test1.txt</option> <option>http://url.to.file/Test2.txt</option> </select> <script> $(document).ready(function() { $('#file-select').change(function () { let loaded_files_list = new Array(); let promise = new Promise(function(myResolve,myReject) { $("#file-select option:selected").each(function () { $.get($(this).val(), function(response) { data = response; // Do something with data loaded_files_list.push($(this).val()); if(loaded_files_list.length == $("#file-select option:selected").length) { myResolve(loaded_files_list); } else { myReject('List is not complete yet'); } }); }); }); promise.then( function(value) { console.log(value); }, function(error) { console.log(error); } ); }); }); </script> </body> </html>

donde los archivos Test1.txt y Test2.txt están alojados en el mismo servidor que la página web. Si utilizo esta configuración me sale el siguiente error:

 Uncaught TypeError: Cannot read properties of undefined (reading 'toLowerCase') at S.fn.init.val (jquery.min.js:2:69494) at Object.success (ajax_test.html:21:40) at c (jquery.min.js:2:28327) at Object.fireWith [as resolveWith] (jquery.min.js:2:29072) at l (jquery.min.js:2:79901) at XMLHttpRequest.<anonymous> (jquery.min.js:2:82355)

No entiendo de donde viene ese error. ¿Dónde está jQuery usando .toLowerCase donde no parece estar definido?

over 3 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Show me some job opportunities
There's an error!