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

268
Views
estoy tratando de enviar una matriz js a php usando axios formdata pero sigue fallando obtengo [objext object] en la consola y si estoy tratando de usar stringify ""

Estoy tratando de publicar una matriz js de claves y valores en php usando axios y estoy realmente perdido gracias por su ayuda

aquí está la matriz que estoy enviando:

 let arr = []; arr["adID"] = uuidv4(); arr["price"] = price; arr["city"] = city; arr["street"] = street; arr["rooms"] = rooms; arr["building_number"] = building_number; arr["entry"] = entry; arr["apartment"] = apartment; arr["user_id"] = 1; sendDataFromJsToPhp("insertAd", arr);

aquí está la parte de axios:

 sendDataFromJsToPhp(type, parametersArray) { this.formData.append("data", "insertAd"); //type to create new ad is insertAd this.formData.append( "parameters",parametersArray); //type to create new ad is insertAd axios({ method: "post", url: this.url, data: this.formData, config: { headers: { "Content-Type": "multipart/form-data" } }, }).then( (response) => { console.log(response.data); this.resultFromServer = response.data; }, (error) => { console.log(error); } ); //this is a work around that will get us array of keys and one of values and will merge them //to get aray that represent the data we got return this.resultFromServer;

}

aquí está el php:

 header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: *"); header("Access-Control-Allow-Methods: *"); header('Content-Type: application/json'); $DATA_RAW = file_get_contents("php://input"); $DATA_OBJ = json_decode($DATA_RAW); $error = ""; if(isset($_POST)&&isset($_POST['data'])) $dataType = $_POST["data"]; if(isset($_POST)&&isset($_POST['parameters'])) $parameters=$_POST['parameters']; print_r($parameters);

los errores presentes cuando dirijo los $parámetros obtengo estos errores: 1) Advertencia : Desplazamiento de cadena no inicializado 0 en 2) b> Error fatal : Error de tipo no detectado: No se puede acceder al desplazamiento de cadena de tipo en cadena en

Muchísimas gracias

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si su matriz usa un valor de clave de cadena, en lugar de un int, stringify ignora ese valor.

Por lo tanto, debe crear un objeto en lugar de una matriz.

es decir;

 let arr = {}; arr.adID = uuidv4(); arr.price = price; arr.city = city; arr.street = street; arr.rooms = rooms; arr.building_number = building_number; arr.entry = entry; arr.apartment = apartment; arr.user_id = 1; sendDataFromJsToPhp("insertAd", arr);

Y en el anexo formData;

 this.formData.append( "parameters", JSON.stringify(parametersArray)); //type to create new ad is insertAd
about 4 years ago · Juan Pablo Isaza Report
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!