Created
August 29, 2018 04:56
-
-
Save shubham7298/49b63f2f9491c8a7967c05d1b7219fc4 to your computer and use it in GitHub Desktop.
Generating Query Params
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
var params = { | |
a : any.value, | |
b : other.value | |
}; // Add any no. of parameters you want to pass separated using "." | |
function paramsChange(params){ | |
var queryString = $.param(params); | |
var queryString = Object.keys(params).map((key) => { | |
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]) | |
}).join('&'); | |
console.log(queryString); | |
updateURL(); | |
function updateURL(){ | |
if (history.pushState) { | |
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?' +queryString; | |
window.history.pushState({path:newurl},'',newurl); | |
} | |
} | |
window.location.reload(); | |
// params changed | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment