Skip to content

Instantly share code, notes, and snippets.

@nrweir
Created June 29, 2018 20:35
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 nrweir/9bf5b4cca1b3f90b6a6e0295afe9ec12 to your computer and use it in GitHub Desktop.
Save nrweir/9bf5b4cca1b3f90b6a6e0295afe9ec12 to your computer and use it in GitHub Desktop.
AJAX call using CustomJS
data = {'x': ["0-7 days", "7-30 days", "31-90 days", ">90 days"],
'All dogs': [41.4391, 34.8107, 15.6709, 4.4533],
'Filtered': [0, 0, 0, 0]}
source = ColumnDataSource(data=data)
callback = CustomJS(args=dict(source=source), code="""
$.ajax({
url: '/_ajax',
data: $("#filter_form").serialize(),
type: 'GET',
success: function(response) {
console.log(response);
var response_data = response;
var data = source.data;
data['Filtered'] = response_data['y_vals'];
source.change.emit();
var resultCount = "Your query returned " + response_data['n_records'].toString() + " results.";
document.getElementById("n_results").innerHTML = resultCount;
},
error: function(error) {
console.log(error);
}
});
""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment