title: Using Ajax to add to cart in Sylius
body: <p>I have followed the tutorial <a href="http://docs.sylius.org/en/latest/cookbook/custom-redirect-after-cart-add-action.html" rel="nofollow noreferrer" title="here">here</a> and am able to change the redirect route. But what i want this to be completed purely with Ajax and for the cart total to be updated automatically. However im having trouble over-riding the javascript in the vendor directory in sylius. Has anyone managed to do this using purely Ajax only?</p>
  
  <p>Ive followed the Sylius cookbook documentation to change the redirect after add to cart detailed here. The redirect class which is created returns a new redirect route: </p>
  
  <pre><code>$newUrl = $this-&gt;router-&gt;generate('your_new_route_name', []); 
  $event-&gt;setResponse(new RedirectResponse($newUrl));
  </code></pre>
  
  <p>Ajax is already used to add to cart and the redirect happens afterwards. I tried changing this code to return a simple response ('Success', 200).</p>
  
  <p>This however causes an error in the script in the vendor directory which handles the ajax request.</p>
  
  <pre><code>$.each(response.errors.errors, function (key, message) {
      validationMessage += message;
  });
  
  Uncaught TypeError: Cannot read property 'errors' of undefined
    at HTMLFormElement.onFailure (app.js:1363)
    at Object.fail (app.js:23)
    at i (app.js:2)
    at Object.fireWith [as rejectWith] (app.js:2)
    at app.js:23
  </code></pre>
  
  <p>The guide tells me to handle this on the frontend but im not entirely sure how I can access this script in the vendor directory. The script is the sylus-add-to-cart.js located in the ShopBundle.</p>
  
  <p>Kind regards</p>
  
  <p>Aaron </p>