I have a code to preventDefault after a form submit, and act accordingly to different conditions. Both condition work, everything works, but after the ELSE condition, the page refreshes. Here is the code:
$('.form_invitation').on 'submit', (e) ->
e.preventDefault()
$('#sending_invite').show()
$.post $(this).prop('action'), $(this).serialize(), (invite) ->
alert(invite.status)
if invite.status
$('#sending_invite').hide()
$('#invite_sent').show()
$('#invite_email').val('')
else
alert('start')
$('#sending_invite').hide()
$('#invite_fail').show()
alert('end')
I put these alerts there, and all of them are shown before page refreshes. I've tried returning false instead of preventingDefault, and is also didn't work. Can anyone see what I am missing?