Skip to content

Instantly share code, notes, and snippets.

@jampow
Created June 2, 2011 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jampow/1005240 to your computer and use it in GitHub Desktop.
Save jampow/1005240 to your computer and use it in GitHub Desktop.
jquery busca ajax
$(function(){
$('#botao_busca').click(function(){
$.ajax({
url: "/buscador/por_nome",
method: "POST",
data: "name=" + $('#campo_busca').attr('value'), //pode passar vários parâmetros como numa url(chave=valor&outrachave=outrovalor)
success: function(data){
//coloca o retorno dentro do elemento com id="resultado"
$('#resultado').append(data);
}
});
});
});
...
def por_nome
@resultado = Modelo.find_by_name(params[:name])
@resultado.to_json
end
...
...
<input id="campo_busca" type="text" />
<input id="botao_busca" type="submit" />
<div id="resultado"> </div>
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment