Pete Winter
asked on
Jquery replace URL parameters
I am replacing my URL parameters using the below code...
then I am trying to get the results using this code...
Example showed on this page: http://www.jquerybyexample.net/2012/06/get-url-parameters-using-jquery.html
The above is fine for fields that have just one value, but some of my field have more than one value. For example...
http://dummy.com/?technology=jquery&technology=php&blog=jquerybyexample
var tech = GetURLParameter('technolog y');
Only gets the first value. How would get all values that are associated to 'technology'?
var myParams = jQuery.param(myParams);
history.replaceState(null, null, "?" + myParams);
then I am trying to get the results using this code...
function GetURLParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
}
}
var tech = GetURLParameter('technology');
Example showed on this page: http://www.jquerybyexample.net/2012/06/get-url-parameters-using-jquery.html
The above is fine for fields that have just one value, but some of my field have more than one value. For example...
http://dummy.com/?technology=jquery&technology=php&blog=jquerybyexample
var tech = GetURLParameter('technolog
Only gets the first value. How would get all values that are associated to 'technology'?
ASKER
You will see from my example the 'technology' param is repeated with a second value. However currently it only outputs one value. How can I output all the technology values as an array?
So you would always want the return from that function to be an array, which would be the case even if there was just one value for that param, that would be okay? And then your calling code would have to be adjusted to expect and deal with an array.
»bp
»bp
ASKER
An array is fine for all if easier. Can you supply an example of what to do please?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
»bp