Last active
September 29, 2015 12:46
-
-
Save joetsoi/3f88d004df0e1df2d6ab to your computer and use it in GitHub Desktop.
ckan api jquery example
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
<html> | |
<body> | |
<div class="search"> | |
<input type="text" id="search-box" placeholder="Dataset" /> | |
<div id="matches"></div> | |
</div> | |
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> | |
<script src="dataset.js"></script> | |
</body> | |
</html> |
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
$(document).ready(function(){ | |
$("#search-box").keyup(function(){ | |
$.ajax({ | |
url: "http://demo.ckan.org/api/3/action/package_autocomplete?callback=?", | |
type: "get", | |
dataType: "jsonp", | |
data:'q='+$(this).val(), | |
success: function(data){ | |
var html = []; | |
$.each(data.result, function(index, d){ | |
html.push( | |
"Dataset: ", d.match_displayed, ", ", | |
"Dataset Name: ", d.name, ", ", | |
"Matched Field: ", d.match_field, ", ", | |
"<br>"); | |
}); | |
$("#matches").show(); | |
$("#matches").html(html); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment