How to send form without refreshing the page?

Asked

Viewed 364 times

0

I made a code that after selecting the radio button he sends to a page but he’s giving refresh and I don’t want it I don’t want it refresh on the page but keep sending and I also want when send it to appear a alert I’m trying to implement this alert and of refresh and so far nothing. Follow my code below:

jQuery:

$(".radioo").click(function(){
        $("#rating").submit();

           $.alert({
            title: 'Atenção',
            content: 'Todos os campos sao obrigatorios!',
            });
            return;
        });

the part of the form is thus:

<form method="post" action="rating.php" id="rating">
<div class="estrelas">
  <input type="radio" id="cm_star-empty" class="radioo" name="fb" value="" checked/>
  <label for="cm_star-1"><i class="fa"></i></label>
  <input type="radio" class="radioo" id="cm_star-1" name="fb" value="1"/>
  <label for="cm_star-2"><i class="fa"></i></label>
  <input type="radio" class="radioo" id="cm_star-2" name="fb" value="2"/>
  <label for="cm_star-3"><i class="fa"></i></label>
  <input type="radio" class="radioo" id="cm_star-3" name="fb" value="3"/>
  <label for="cm_star-4"><i class="fa"></i></label>
  <input type="radio" class="radioo" id="cm_star-4" name="fb" value="4"/>
  <label for="cm_star-5"><i class="fa"></i></label>
  <input type="radio" class="radioo" id="cm_star-5" name="fb" value="5"/>
</div>
</form>

How to make the implementations in this code from it send the form to the page without giving rating refresh and as soon as you send a message like your implementations have been saved successfully?

1 answer

7


Using AJAX:

$(".radioo").click(function() {
  var option = $('input[type="radio"]:checked').val();
  $.ajax({
    type: "POST",
    url: "rating.php",
    data: { poll_option : option },
    success: function(response) {
      alert('Dados enviados.');
    }
  });
});

Adapted from a similar question in Soen

  • Thank you guy perfect function

Browser other questions tagged

You are not signed in. Login or sign up in order to post.