how to send name and value of a submit button via ajax

0

I'm using the obj. FormData () to send the different input controls of a form but the problem is that it excludes the input submit that sent the form, of course it does chrome but the other browsers do not. I have several submit s. In the documentation of the W3C says that a submit button of the various buttons submits only the one that sends the form is successful but this is not met with ajax except in chrome. in the backend I am working with PHP and what I want is: what submit button sent the form and thus do one thing or another thing but I do not get the submit button to collect with the global variable $ _POST [''] and I repeat this does not happen in chrome. for which serial the adequate solution for this problem.

    
asked by Blas 08.06.2016 в 16:07
source

1 answer

1

You can try this way:

In the independent inputs of the programming language that you manage, send all the parameters with the id of the field.

You create the input with and you add the name.

<input id="nombre" name="nombre" type="text" />

You create a button to send all the parameters

<input id="BotonEnviar" name="BotonEnviar" type="submit" />

Then with jQuery valid if that button was clicked.

$('#boton_cargar').click(function() { });

You create the variable which contains the parameter you just sent

var nombre = $("#nombre").val(); 

Then you create the ajax and pass it the php form + the parameters

$.ajax({ 
type: "GET", 
url: 'resultados.php?nombre='+nombre, 
success: function(data) { 

If the parameters were sent correctly I enter the result in a div

$('#resultados').html(data); 
$('#resultados div').slideDown(1000); 
} 

$(document).ready(function(){ 
$('#boton_cargar').click(function() { 

var nombre = $("#nombre").val(); 

$.ajax({ 
type: "GET", 
url: 'resultados.php?nombre='+nombre, 
success: function(data) { 
$('#resultados').html(data); 
$('#resultados div').slideDown(1000); 
} 
}); 
}); 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<input id="nombre" name="nombre" type="text" />
    
answered by 08.06.2016 в 17:00