If I have the following: http://www.domain.com/myscript?x1=v1&x2=v2
And I would like to reload this page with additional data {x3: v3, x4: v4}. What is the simple way to do without manipulating the original url?
If I have the following: http://www.domain.com/myscript?x1=v1&x2=v2
And I would like to reload this page with additional data {x3: v3, x4: v4}. What is the simple way to do without manipulating the original url?
Reload the page using window.location
var original_url = window.location;
window.location = original_url + "&x3=data3&x4=data4";
Edit: You can update values from url using this function:
/**
* http://stackoverflow.com/a/10997390/11236
*/
function updateURLParameter(url, param, paramVal){
var newAdditionalURL = "";
var tempArray = url.split("?");
var baseURL = tempArray[0];
var additionalURL = tempArray[1];
var temp = "";
if (additionalURL) {
tempArray = additionalURL.split("&");
for (i=0; i<tempArray.length; i++){
if(tempArray[i].split('=')[0] != param){
newAdditionalURL += temp + tempArray[i];
temp = "&";
}
}
}
var rows_txt = temp + "" + param + "=" + paramVal;
return baseURL + "?" + newAdditionalURL + rows_txt;
}
You can use it:
var x1 = updateURLParameter(window.location.href, 'x1', 'updatedData1');
var url = updateURLParameter(x1, 'x2', 'updatedData2');
window.location = url;