How to upload more than one AJAX - PHP id?

Asked

Viewed 81 times

1

In the case below I am sending the ID data: id_motor... And if I want to send another ID together, like the id_motor and the id_model, as I would?

		$(function(){
			$('#id_motor').change(function(){
				if( $(this).val() ) {
					$('#id_ano').hide();
					$('.carregando').show();
					$.getJSON('sub_ano.php?search=',{id_motor: $(this).val(), ajax: 'true'}, function(j){
						var options = '<option value="">Escolha o Ano</option>';	
						for (var i = 0; i < j.length; i++) {
							options += '<option value="' + j[i].id + '">' + j[i].ano + '</option>';
						}	
						$('#id_ano').html(options).show();
						$('.carregando').hide();
					});
				} else {
					$('#id_ano').html('<option value="">– Escolha o Ano –</option>');
				}
			});
		});	

On the other side I’m recovering like:

$id_motor = $_REQUEST['id_motor'];

and would have to recover another, example:

$id_motor = $_REQUEST['id_motor'];

$id_template = $_REQUEST['id_template'];

1 answer

2


I use the "data" array to pass the parameters using jquery ajax:

$('#id_motor').change(function(){

    $.ajax({
        url: 'sub_ano.php',
        type: 'GET',
        dataType: 'json', //espera o retorno em json
        data: {
            //aqui você passa quantos parametros precisar
            id_motor: $("#meuMotor").val(), //id do campo id_motor
            id_outro : $("#outro_id").val(), // id do campo outro_id
        },
        success: function(j){
            var options = '<option value="">Escolha o Ano</option>';    
            for (var i = 0; i < j.length; i++) {
                options += '<option value="' + j[i].id + '">' + j[i].ano + '</option>';
            }   
            $('#id_ano').html(options).show();
            $('.carregando').hide();
        },
        error: function(){
            Alert("Erro ao processar requisição"); //deu algum erro na requisição
        }

    }); //fim do ajax

});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.