I'm creating a page in PHP that does a query in a JSON / PHP via ajax and I need it to send to the URL, form variables so I can do 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();
});
})
})