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

191
Views
no se pudo configurar la cookie desde la reacción de la interfaz

Tengo un servidor de nodo backend, que tiene dos apis: para configurar y obtener cookies.

Código backend para configurar y obtener cookies:

Servidor: servidor local: 4001

 router.get("/addCartToCookie", function(req, res){ let options = { maxAge: 1000 * 60 * 15, httpOnly: true, }; let cartData = { name: req.body.name, slug: req.body.slug, productPictures: req.body.productPictures, price: req.body.price, description: req.body.description, quantity: req.body.quantity, }; // Set cookie res.cookie("cartName", cartData, options); // options is optional res.send("Cart Added to Cookie"); }); //To get the cookie router.get("/getCartFromCookie",function(req, res){ res.send(req.cookies); console.log(req.cookies["cartName"]); });

Código de reacción de frontend para llamar a la API al hacer clic en el botón:

Cliente: servidor local: 3001

 const addToCartCookie = () => { console.log("Calling add to cart cookie"); axios .get("http://localhost:4001/api/addCartToCookie", { name: product.name, slug: product.slug, productPictures: product.productPictures[0].img, description: "sabdsjbfjsd", price: product.storePrice, quantity: itemCount, }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); };

OnClick llama a la API anterior,

 <Button type="primary" onClick={() => { addToCartCookie(); }} > ADD TO CART </Button>

No establece una cookie en el navegador del cliente al hacer clic en el botón. Mientras revisa la pestaña de red, la API se llama bien, pero el único problema es que no está configurando la cookie en el lado del cliente.

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

0

En la interfaz, configure el encabezado allow-credentials en verdadero, y en la API, configure el encabezado Origin-Allow-Credentials en verdadero, guarde y luego reinicie su servidor. Y luego, después de guardar el front-end, haga clic con el botón izquierdo en el ícono de recarga del navegador en su sitio web, "haga clic en recarga dura y elimine el caché". Luego vuelve a intentarlo.

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!