Skip to content

Instantly share code, notes, and snippets.

@eatoncw
Created March 7, 2018 20:26
Show Gist options
  • Save eatoncw/279579ca5ec76b07b9e89d4221b5139c to your computer and use it in GitHub Desktop.
Save eatoncw/279579ca5ec76b07b9e89d4221b5139c to your computer and use it in GitHub Desktop.
dynamically generate params for GET request to update products page based on user-selected filters
//uses jquery to send request to rails 5 built api-only backend
$('.sales-filters input').on('click', function() {
var params = {};
var filters = $('.sales-filters input:checked'); //get array of all checked radio buttons
for (i = 0; i < filters.length; i++) {
params[filters[i].name] = filters[i].value //dynamically create params for GET request based on name and value attributes
}
var url = window.location.origin + '.....'
fetchAndPaginate(url,params)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment