jquery for ruby on rails

Posted by Cezar on Stack Overflow See other posts from Stack Overflow or by Cezar
Published on 2010-04-21T12:34:44Z Indexed on 2010/04/21 12:53 UTC
Read the original article Hit count: 250

Hello,

I am tying to use this code http://gist.github.com/110410 to dump Prototype in favor of jQuery but I do have a problem.

This is my HTML (a link_to generated link):

<a onclick="var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', 'Mi6RcR6YDyvg2uNwGrpbeIJutSHa2fYboU37wSDE7AU='); f.appendChild(s);f.submit();return false;" class="post add_to_cart " href="/line_items?product_id=547">Add to cart</a>

Issue:

Everything works as it should except that the page does a reload. I suspect that the submit gets thru which causes a page reload.

Is there an elegant way to prevent that ? return false; doesn't seem to cut it in this case.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about jQuery