Create a gist now

Instantly share code, notes, and snippets.

What would you like to do? JSONP embedded search example

Example of embedded search, and a tribute to Cory Doctorow ;) tnx to @thedod

See it live here.

If you want to embed this (or any other search) in an existing page:

  • Remove first and last line and paste this where you want it in the <body/>.
  • Change query to whatever you want to search (and maybe change limit).
  • Optionally, do some css (please fork this if you do something cool).
<script type="text/javascript" src=""></script>
<script type='text/javascript'>
var query = "doctorow"
var element = "#thorrents"
var limit = 5
// TODO: jquery function - $("element").thorrents()
var domain = ""
var url = 'http://'+domain+'/search/'+query+'.json?callback=?'
$.getJSON(url, function(data) {
$.each(data.results, function(idx, result) {
$(element+" ul").append("<li><a href='"+result.magnet+"'><span>"+result.seeds+"</span>""</a></li>")
if (idx+1 >= limit)
return false
<style text='type/css'>
#thorrents li {
display: block;
#thorrents li span {
display: block;
float: left;
text-align: right;
width: 80px;
margin-right: 12px
<div id='thorrents'></div>
"results": [{
"name": "ubuntu desktop 10.10 i386",
"magnet": "magnet:?xt=urn:btih:bcf2e587afd4d3....80%2Fannounce",
"seeds": "157"
}, {
"name": "Ubuntu 10.10 amd64",
"magnet": "magnet:?xt=urn:btih:4af6fb7cbfb87....80%2Fannounce",
"seeds": "63"
}, {
"name": "Ubuntu Ultimate Edition",
"magnet": "magnet:?xt=urn:btih:429f2330241....80%2Fannounce",
"seeds": "36"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment