I have a bootstrap button, that i have embedded into a form. The form requests a php file with ajax. But i Cant get the button to work like a link?
The html code is for the bootstrap button is :
<a id="btn-login" href="#" class="btn btn-success">Login</a>
and the js is :
<script>
$(document).ready(function() {
$('.myform').on('submit',function(){
// Add text 'loading...' right after clicking on the submit button.
$('.output_message').text('Loading...');
var form = $(this);
$.ajax({
url: form.attr('action'),
method: form.attr('method'),
data: form.serialize(),
success: function(result){
if (result == 'success'){
$('.output_message').text('Message Sent!');
} else {
$('.output_message').text('Error Sending email!');
}
}
});
// Prevents default submission of the form after clicking on the submit button.
return false;
});
});
</script>