Created
June 2, 2011 20:32
-
-
Save jampow/1005240 to your computer and use it in GitHub Desktop.
jquery busca ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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); | |
} | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
def por_nome | |
@resultado = Modelo.find_by_name(params[:name]) | |
@resultado.to_json | |
end | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<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