I capture several inputs (the value) dynamically in the following way:
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<input type="text" name="prueba" class="form-control-file nombrePaisIdioma"><br/><br/>
<input type="text" name="prueba" class="form-control-file nombrePaisIdioma"><br/><br/>
<input type="text" name="prueba" class="form-control-file nombrePaisIdioma"><br/><br/>
<input type="text" name="prueba" class="form-control-file nombrePaisIdioma"><br/><br/>
<input type="button" onclick="x();" class="btn btn-primary" id="enviardoc" value="Enviar Documentos">
<script type="text/javascript">
function x(){
var nombres_paises = {};
$('.nombrePaisIdioma').each(function() {
nombres_paises[$(this).attr('id')] = $(this).val();
console.log(nombres_paises);
});
$.ajax({
type : 'POST',
data : {'nombres_paises': JSON.stringify(nombres_paises)},//capturo array
url : 'pruebacolor2.php',
success : function(e){
console.log(e);
}
});
}
</script>
So far we are doing well, since I capture them all.
The problem is that in PHP, only 1 comes, the last one:
<?php
$data = json_decode($_POST['nombres_paises']);
var_dump($data);
?>
I hope you can help me, because I do not know what the problem is.
Thanks