Ajax不适用于我的所有表单

I'm using ajax to validate my forms but my form is in a while loop in php and my request ajax work only on my first forms.

My code :

Ajax:

<script type="text/javascript">

$(document).ready(function() {
$('#form_entourage').on('submit', function() {

    var nom = $('#entourage_nom_1').val();
    var prenom = $('#entourage_prenom_1').val();

    if(nom == '' || prenom == '') {
        alert('Les champs doivent êtres remplis');
    } else {
        $.ajax({
            url: $(this).attr('action'),
            type: $(this).attr('method'),
            data: $(this).serialize(),
            dataType: 'json',
            success: function(json) {
                if(json.reponse == 'ok') {
                    alert('Tout est bon');
                } else {
                    alert(''+ json.reponse);
                }
            }
        });
    }
    return false;
});
});

</script>

PHP Forms: with my loop while and my ajax work just on 1 form. ex: when i have 3 member my ajax validation work only on the first member and on my second member i redirected on my php validation.

        while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
       printf ("

              <h3>Membre ".$numero_membre."</h3>");
       $numero_membre = $numero_membre+1;
       printf ("
<form class='form-horizontal' id='form_entourage' method='post' action='modif/mod_entourage.php' style='height: 670px;'>
          <span class='span5 control-group'>
            <label for='entourage_nom_1'>Nom</label>
            <input class='span5' type='text' name='entourage_nom_1' value='".$row["nom"]."' >
            <input type='hidden' name='id_entourage' value='".$row["id_entourage"]."' >
          </span>
          <span class='span5 control-group'>
            <label for='entourage_prenom_1'>Prénom</label>
            <input class='span5' type='text' name='entourage_prenom_1' value='".$row["prenom"]."' >
          </span>
<span class='span5 control-group'>
<input type='submit' name='mod_entourage' id='mod_entourage' class='btn btn-primary pull-right' value='Modifier' /></span>
          </form>
          <div class='clear'></div>
");
    }

Someone can help me please?

your are using same id for all forms . append a counter variable in form ids. it will surely works for you. your form id can be like this

 <form id="form_entourage_ 1" data-idval="1" .. >..Similarly change id for other elements</form>

 <form id="form_entourage_ 2" data-idval="2" .. >..</form>

 <form id="form_entourage_ 3" data-idval="3" .. >..</form>

Jquery :-

   $("[id^='form_entourage']").on('submit', function() {
         var clicked_id = $(this).data('idval');

         var nom = $('#entourage_nom_'+clicked_id).val();
         var prenom = $('#entourage_prenom_'+clicked_id).val();
         ...........
         ...........
    });

You are using only one id for your forms, that's why it only works for first time.

Ok, this was answered, but I think that with classes it will do the same better (no additional markup required, no ids, no numbers, XD) :

 $("form.AJAX").on('submit', function() {
   // Catching the DOM element which trigger the event 
   var $form = $(this);

   // Now, from the form which trigger the submit event, take the values
   var nom    = $form.find('input[name="entourage_nom"]').val();
   var prenom = $form.find('input[name="entourage_prenom"]').val();
   ...........
   ...........
 });

 //HTML:

<form class='form-horizontal AJAX' id='form_entourage' method='post' action='modif/mod_entourage.php' style='height: 670px;'>
  <span class='span5 control-group'>
    <label for='entourage_nom'>Nom</label>
    <input class='span5' type='text' name='entourage_nom' value='".$row["nom"]."' >
    <input type='hidden' name='id_entourage' value='".$row["id_entourage"]."' >
  </span>
  <span class='span5 control-group'>
    <label for='entourage_prenom'>Prénom</label>
    <input class='span5' type='text' name='entourage_prenom' value='".$row["prenom"]."' >
  </span>
  <span class='span5 control-group'>
    <input type='submit' name='mod_entourage' id='mod_entourage' class='btn btn-primary pull-right' value='Modifier' />
  </span>
</form>

<!-- This second FORM will also work, even having the same markup -->
<form class='form-horizontal AJAX' id='form_entourage' method='post' action='modif/mod_entourage.php' style='height: 670px;'>
  <span class='span5 control-group'>
    <label for='entourage_nom'>Nom</label>
    <input class='span5' type='text' name='entourage_nom' value='".$row["nom"]."' >
    <input type='hidden' name='id_entourage' value='".$row["id_entourage"]."' >
  </span>
  <span class='span5 control-group'>
    <label for='entourage_prenom'>Prénom</label>
    <input class='span5' type='text' name='entourage_prenom' value='".$row["prenom"]."' >
  </span>
  <span class='span5 control-group'>
    <input type='submit' name='mod_entourage' id='mod_entourage' class='btn btn-primary pull-right' value='Modifier' />
  </span>
</form>

Then even if ALL your forms have EXACTLY the same markup, they will work perfectly, because you're referring only to the one who trigger the submit: Save coding!