Josh Hernandez Josh Hernandez - 2 months ago 6
HTML Question

Multiple Variable in Ajax

I am trying to send 2 variable from my comobox but is does not work, it only works when I send 1 here is the ajax code:

$(document).ready(function()
{
$(".clase").hide();
$(".ruta").change(function(){
var id=$(".rutas").val();
var dataString = 'id='+ id;
$.ajax
({
type: "POST",
url: "asientos.php",
data: dataString,
cache: false,
success: function(html)
{
$(".clase").show();
$(".clase").change(function(){
var id=$(".rutas").val();
var cla=$(".clase").val();
var dataString = 'id='+ id;
var data = 'cla'+ cla;
$.ajax
({
type: "POST",
url: "asientos.php",
data: dataString,data,
cache: false,
success: function(html)
{
$(".asientos").html(html);
}
});
});
}
});
});
});


Now here is my html only showing the combo part cause i have multiple components in the form

<label class="ruta">Rutas </label> <select name="rutas" id="rutas" class="rutas" >
<?php include 'rutas.php'; ?>
</select>
<label class="clase">Clases </label><select name="clase" id="clase" class="clase">
<option value="A">Clase Ejecutiva</option>;
<option value="B">Clase Media</option>;
<option value="C">Clase Economico</option>;
</select>

Answer

Note that you are using two ajax request here, you can only use second request and if you want to send two select box value by using ajax than this will not work:

var dataString = 'id='+ id; 
var data = 'cla'+ cla;

You can just simply use:

var dataString = 'id='+ id+'&cla='+cla;

In ajax, no need to use like that:

data: dataString,data,

you can just use like that:

data: dataString,
Comments