Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
¿Cómo publicar una matriz de objetos en un servidor Node.js?

¿Cómo se publica una matriz de objetos que contienen datos de usuario en el servidor donde se puede verificar? Estoy tratando de obtener datos de un formulario de pedido para pasar a un servidor para verificarlos y luego mostrarlos en otra página a la que redirijo.

 const addProducts = (ev) => { ev.preventDefault(); let products = []; for(let k = 0; k < counter+1; k++) { let bund = 'Bundled' + k; let sing = 'Single' + k; let unit = 'BundledUnits' + k; let name = 'ProductTitle' + k; let quant = 'Quantity' + k; let lPrice = 'ListPrice' + k; let instruct = 'Instructions' + k; if(document.getElementById(asin)) { if(document.getElementById(bund) && document.getElementById(bund).checked) { if(document.getElementById(unit).value) { let bundProduct = { id: k.value, "Bundled": "true", "Product": document.getElementById(name).value, "quantity": document.getElementById(quant).value, "ListPrice": document.getElementById(lPrice).value, "Instructions": document.getElementById(instruct).value }; products.push(bundProduct); } } else if(document.getElementById(sing) && document.getElementById(sing).checked) { let singProduct = { id: k.value, "Bundled": "false", "Product": document.getElementById(name).value, "quantity": document.getElementById(quant).value, "ListPrice": document.getElementById(lPrice).value, "Instructions": document.getElementById(instruct).value }; products.push(singProduct); } } console.log(k); } let order = sessionStorage.setItem('order', JSON.stringify(products));
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Puede usar fetch o bibliotecas como axios .

Verifique esta pregunta sobre cómo hacer una solicitud POST con fetch: Fetch: POST JSON data

Ejemplo de función de solicitud POST con axios :

 const sendToServer = async (products) => { try { // store response in variable if needed const res = await axios.post( "/your_api/products", products // products you want to post ); // return data in case return res.data } catch (error) { console.log(error); } } // implement this function where you need it sendToServer(products)

o consulte los ejemplos POST en la documentación de axios : https://axios-http.com/docs/post_example

 // Send a POST request axios.post('/user', { firstName: 'Fred', lastName: 'Flintstone' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); // Send a POST request axios({ method: 'post', url: '/user/12345', data: { firstName: 'Fred', lastName: 'Flintstone' } });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda