Send more than one parameter in GET request

1

I use the following code to send a parameter in a Ajax request of type GET .

$('#cidades').load('cidades.php?estado=' + $('#estados').val());

How do I pass also a parameter called recurso ?

    
asked by anonymous 09.12.2015 / 16:00

4 answers

9

Another way is to send an object as a "second parameter," according to the jQuery.load () documentation.

var parametros = {
    estado: $('#estados').val(),
    recurso: $('#recurso').val()
};

$('#cidades').load('cidades.php', parametros, callback);

var callback = function() {
    //do something
}

It is still possible to call a callback function as the third parameter.

    
09.12.2015 / 16:13
5

If you continue with this concatenation there in your code, it would be preferable to use the $.param function of jQuery.

var dados = {
   estado: $('#estados').val()
}

var  url = 'cidades.php?' + $.param(dados)

But anyway I consider the answer to the @PedroJuniorCamara better

link

    
09.12.2015 / 16:20
4

You just have to separate the variables with the & character

$('#cidades').load('cidades.php?estado='+$('#estados').val()+'&recurso=seuRecurso');

If you need to use more parameters, I think it's much better to do it the way Peter and Wallace said.

    
09.12.2015 / 16:13
3

Parameters must be separator with a "&" this way:

link.php?param1=valor&param2=valor

Your example would look something like this:

cidades.php?estado=valor&cidade=valor
    
09.12.2015 / 16:09