The following code is designed to execute a purely ajax POST request, instead, it seems to execute POST through ajax, and then the browser goes to the answer.
HTML ...
<div id="bin"> <form class="add" method="post" action="/bin/add/"> <p>I'm interested! Save for later.</p> <input type="hidden" name="product_id" value="23423"> <input type="submit" value="Save"> </form> <form style="display:none;" class="remove" method="post" action="/bin/remove/"> <p>I changed my mind--I'm not interested.</p> <input type="hidden" name="product_id" value="23423"> <input type="submit" value="Unsave"> </form> </div>
jQuery ...
$('#bin form').submit(function() { $.post($(this).attr('action'),{ success: function(data) { $(this).hide().siblings('form').show() }, data: $(this).serialize() }); return false; })
As far as I understand, the string return false; should mean that no matter what calls the submit function or presses the submit button or presses the enter key, it means that my function will be executed and the browser will not move to /bin/add or /bin/remove . But for some reason, the browser changes pages.
Any idea what I'm doing wrong here? Thanks.
Chris W.
source share