0
I have a modal to mark friends, when the user clicks to mark, I call the onclick that makes the request to the controller.
I want to send a message of success to the user, I have a div with None display and I want to make it visible when the POST occurs.
However, with the POST the page is reloaded and the div is back to display None without even appearing the message.
<div class="alert alert-success" role="alert" style="display:none;">
Amigo marcado!</div>
function marcar(e){
$.ajax({
url: '/MarcarAmigo/MarcarAmigos/',
type: "POST",
cache: false,
data: {'publicacao': publicacao, 'amigos_marcados': amigos_marcados},
success: function () {
$(".alert").css("display", "block");
}
}); }
This does not serve because I need the POST for the request on the server and save the data in the database, is a Submit button because I need the Submit.
– Bianca C.
You can put the preventDefault in the form Submit, do the ajax with the form data, and in return ajax do the same thing
– evandrobm
@Biancac. I edited the answer with an example
– evandrobm
@Biancac. That solved your problem?
– evandrobm
No, as I said e.preventDefault() takes the Submit function from my form
– Bianca C.
But do you need the form to be submitted? I thought the form action was done by the AJAX request
– evandrobm
What is your form action and what does it do? And this URL
/MarcarAmigo/MarcarAmigos/
call on Ajax does what?– evandrobm