0
I am creating a page in PHP that makes a query in a JSON/PHP via ajax and I need it to send to the URL, the form variables so I can make a query in this JSON/PHP.
HTML:
<form method="GET" name="formularioBusca"> <input type="text" id="from-airport" name="Origem" class="form-control" placeholder="Onde você esta?" autocomplete="off" required="required">
<input type="text" id="to-airport" name="Destino" class="form-control" placeholder="Para onde você quer ir?" autocomplete="off" required="required">
<button class="btn btn-buscar-voos" id="buscarVoos" >BUSCAR VOOS</button></form>
Javascript:
$(document).ready(function(){$('#from-airport').blur(function(){
$('#buscarVoos').on('click', function(e){
$('#from-airport').blur(function(){
var partida = $(this).val();
var palavras = partida.split(' ');
var origem = [palavras.pop()];
sigla = origem.toString().replace(/"/g, "").replace(/'/g, "").replace(/\(|\)/g, "");
console.log(sigla);
})
$('#to-airport').blur(function(){
var destino = $(this).val();
var saida = destino.split(' ');
var origem = [saida.pop()];
siglaDestino = origem.toString().replace(/"/g, "").replace(/'/g, "").replace(/\(|\)/g, "");
console.log(siglaDestino);
})
$.ajax({
url: 'api.php',
type: 'GET',
dataType: 'html'
})
.done(function(data){
console.log(data);
$('#dynamic-content').html('');
$('#exibeVoos').html(data);
$('#modal-loader').hide();
})
.fail(function(){
$('#dynamic-content').html('<i class="glyphicon glyphicon-info-sign"></i> Aguarde...');
$('#modal-loader').hide();
});
})
})
It is necessary to create a button or check that both fields are filled. The way you’re doing, you’re sending the data before it’s even filled out.
– Valdeir Psr
Oh yes, I forgot to ask the question, $('#buscarVoos'). on('click', Function(e){.. ..... })
– Cristiano Facirolli
If possible click on [Edit] and change your code if necessary.
– Valdeir Psr
I changed, Thank you! =)
– Cristiano Facirolli