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
?
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
?
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.
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
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.
Parameters must be separator with a "&" this way:
link.php?param1=valor¶m2=valor
Your example would look something like this:
cidades.php?estado=valor&cidade=valor