How to submit form without giving refresh on the page?

0

I made a code that after selecting the radio button it sends to a page but it is giving refresh and I do not want it I want it not refresh on the page but keep sending and also I want when sending it appears a alert I'm trying to implement this from alert and 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 looks like this:

<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 send it form to the rating page without giving refresh and as soon as it sends a message of type have your implementations been successfully saved?

    
asked by anonymous 23.10.2015 / 00:06

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 the SOEn

    
23.10.2015 / 00:50