-1
I am sending an information with ajax, but I would like to send two at once. It would be possible to adapt the code below for this ?
<select name="sex" class="" required>
<option value="1"> Woman </option>
<option value="2">Man </option>
</select>
<select name="country" class="country select" required>
<option value="1">Exemple 1</option>
<option value="2">Exemple 2</option>
<option value="3">Exemplo 3</option>
</select>
The javascript is this
$(document).ready(function()
{
$(".country").change(function()
{
var country_id=$(this).val();
var post_id = 'id='+ country_id;
$.ajax
({
type: "POST",
url: "../conexao/ajax.php",
data: post_id,
cache: false,
success: function(cities)
{
$(".city").html(cities);
}
});
});
});
In the php file you receive, I have this
<?php
include('conexcao.php');
if($_POST['id']){
$id=$_POST['id'];
$sex = $_POST['sex'];
if($id==0){
echo "<option>Selecione seu nome</option>";
}else{
$sql = mysqli_query($conn,"SELECT * FROM `teste` WHERE sex = $sex");
while($row = mysqli_fetch_array($sql)){
echo '<option value="'.$row['id'].'">'.$row['nome'].'</option>';
}
}
}
?>
Hello, first thanks for trying to help. I made the replacement as you suggested, on the part of my ajax. REPLACES >> date: post_id, << by the code you said, but it didn’t work... :(
– Navegador
Add the class="sex" in the SEX input , delete these two lines " var country_id=$(this). val(); "and "var post_id = 'id='+ country_id;" . Now make sure it doesn’t work. and put the code I sent you instead of "DATA" in ajax.
– Bartollo
Perfect, it worked Bartollo, you’re beast, hugs !
– Navegador