Skip to content

Instantly share code, notes, and snippets.

@alexwebgr
Created May 30, 2019 09:19
Show Gist options
  • Save alexwebgr/4ab14f4c129f68c1155517d3d71467f5 to your computer and use it in GitHub Desktop.
Save alexwebgr/4ab14f4c129f68c1155517d3d71467f5 to your computer and use it in GitHub Desktop.
URL helper
// requires https://medialize.github.io/URI.js
function updateURL(url, params) {
let new_url = new URI(url);
$.each(params, function (value) {
if (params[value] !== undefined) {
new_url.setSearch(value, params[value]);
} else {
new_url.removeSearch(value);
}
});
return new_url.href();
};
// usage
$.get(updateURL('/path/to/url', {key: 'value', key2: 'value2'}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment