0

i have the following url

http://bulk-click.dasdasda.com/asdas/adClick?d=scsdc%20cdcsc%20cdscsd

i use this code to get the paramertes but my d=scsdc cdcsc cdscsd instead of d=scsdc%20cdcsc%20cdscsd how can i make sure d will remain equal to scsdc%20cdcsc%20cdscsd the code is:

    pl = /\+/g, // Regex for replacing addition symbol with a space
    search = /([^&=]+)=?([^&]*)/g,
    decode = function(s) {
        return decodeURIComponent(s);
    },
    query = urlEncode.search.substring(1);
    //console.log(query);
result = {};
while ((match = search.exec(query)))
    result[decode(match[1])] = decode(match[2]);
for (let key in result) {
    let value = result[key];
    paramsData[key] = value;
}
biillitil
  • 141
  • 1
  • 12
  • Does this answer your question? [How to get the value from the GET parameters?](https://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-get-parameters) – Peter B May 04 '20 at 08:14
  • 1
    You are decoding your matches. `decodeURIComponent()` will convert `%20` into empty whitespace. – Terry May 04 '20 at 08:15
  • how can i prevent it from converting %20 to whitespace? – biillitil May 04 '20 at 08:19
  • When you get a URL parameter it is decoded automatically, which is what you most likely want, e.g. the original string sent by the producer. If you want to encode to send it on as a URL parameter to another consumer you can always do so using `encodeURIComponent()` – Peter Thoeny Jun 11 '20 at 18:50

0 Answers0