Created
May 30, 2019 09:19
-
-
Save alexwebgr/4ab14f4c129f68c1155517d3d71467f5 to your computer and use it in GitHub Desktop.
URL helper
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
// 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