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

323
Views
JS: intento de enviar una matriz en una solicitud POST AJAX asíncrona (a PHP)

Estoy tratando de enviar una solicitud POST que contiene una matriz, pero la matriz aparece vacía en la carga útil. Al registrar la matriz en la consola, se muestra que tiene una longitud de 2 (esperada) y puedo ver los valores.

No entiendo qué estoy haciendo mal, todos los artículos que he leído han sido sobre una matriz que no muestra los valores esperados o que regresa indefinida; Puedo ver claramente que los valores están en la matriz cuando se envían a la consola. ¿Por qué esto no se refleja en la solicitud POST? También recibo indefinido si intento consolar. registrar un valor específico.

es decir console.log(items[0]); //returns undefined

Fragmento de código:

 function callPHP(items) { console.log(items); var xhr = new XMLHttpRequest(); var data = items; var postUrl = *link*; xhr.open('POST', postUrl, true); xhr.send(data); xhr.onreadystatechange = function() { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("Got response 200!"); } }; } function getUserInfo(aCallback){ var items = []; chrome.identity.getProfileUserInfo({'accountStatus': 'ANY'}, function(info) { email = info.email; items.push(email); items.push("test"); }); aCallback(items); } document.onreadystatechange = function () { if (document.readyState === "interactive") { getUserInfo(callPHP); } };

Realmente agradecería cualquier ayuda, ya que he estado atascado en esto durante horas y siento que me estoy perdiendo algo muy obvio. Si necesita más aclaraciones sobre mi código o su contexto, ¡hágamelo saber!

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!