Friday, 8 December 2017

Get array from url with JavaScript

I have Url with parameters i can get all parametrs except
arrays this is my url
decoded:



name=myname&type=Restaurant
Cuisine Moderne / Créative&heure=06 :00 - 06
:30&nbrPers=10&service[]=Canbeprivatized&service[]=Englishspoken&service[]=Françaisparle&option[]=Check&option[]=CreditCard&typeProfile=Amateur


And
this is my JavaScript
function:



function
getUrlParameter(sParam) {
var sPageURL
=decodeURIComponent(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];

}

}
}


alerts
for test:



var name =
getUrlParameter('name');
alert("name ;"+name);// show : myname
var
service= getUrlParameter('service[]');
alert("servoce:"+service);// show
:only "Canbeprivatized" i cant get the others
service[]


How can i
get all service[] and option[]
??

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...