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

152
Views
Añadir al carrito: evitar actualizar la página

Tengo la siguiente configuración: https://jsfiddle.net/uosLke60/

 input.Add_To_Cart_Button { background-color: #000; color: #fff; border: none; font: inherit; cursor: pointer; font-size: 13px; margin-bottom: 40px; width: 120px; -webkit-appearance: none; border-radius: 0; }
 <div class="Product_Card_Button"> <form method="post" action="/cart/add"> <quantity-input class="quantity" style="width: 120px; min-height: 25.4px; display: inline-flex;"> <button class="quantity__button no-js-hidden" name="minus" type="button"> - </button> <input class="quantity__input" type="number" name="quantity" id="quantity" min="1" value="1" style="text-align: center;"> <button class="quantity__button no-js-hidden" name="plus" type="button">+</button> </quantity-input> <br> <input type="submit" value="Add to cart" class="Add_To_Cart_Button" /> </form> </div>

Cuando se presiona el botón Agregar al carrito, la página se actualiza. ¿Cómo puedo ajustarlo para que el producto se agregue al carrito sin actualizar la página? Probé varias soluciones de jQuery sugeridas en otras publicaciones, pero no tuve suerte. Cualquier sugerencia sería útil. Gracias.

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

0

Debe escuchar el evento de envío en su formulario y:

  1. llame a event.preventDefault() que bloquea la acción predeterminada (en su caso, el envío del formulario)
  2. return false , que finalmente cancela el evento

yo haría algo como esto

 function handleAddToCart(form) { const url = form.getAttribute("action"); const formData = new FormData(form); doSomePost(url, formData); } // Cache this if possible document.querySelector("[add-to-cart-form]") .addEventListener("submit", (e) => { e.preventDefault(); handleAddToCart(e.target); return false; });

También actualicé tu violín => violín

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!