Removing value% 20 from get method

Removing% 20 in the get method?

var c=new Array(a); (eg: a={"1","2"}) window.location="my_details.html?"+ c + "_"; 

and in my_details.html:

 var q=window.location.search; alert("qqqqqqqqqqqqq " + q); var arrayList = (q)? q.substring(1).split("_"):[]; var list=new Array(arrayList); alert("dataaaaaaaaaaaa " + list + "llll " ); 

and in the "list" of his dusplaying me "1%202" ;

How can I remove this value %20 =space ?

thanks

+6
source share
4 answers

just use this:

 alert("dataaaaaaaaaaaa " + decodeURIComponent(list) + "llll " ); 

This should decode %20 to space

look here: http://www.w3schools.com/jsref/jsref_decodeURIComponent.asp

+7
source

If there is a space in parameter (s), %20 (URL encoding) is required. You cannot pass a space in a GET request.

If you need to avoid this, use POST .

0
source

As far as I can see, the problem occurs on this line:

 window.location="my_details.html?"+ c + "_"; 

It can be written as:

 window.location="my_details.html?"+ c.toString() + "_"; 

By default .toString() JavaScript Array will use a delimiter,, i.e.

 var str = ["1", "2", "3"].toString(); // 1,2,3 

In your example, the separator used is a space. This would be modified by something that changed the default .toString() default Array.prototype to Array.prototype . Try using the following:

 window.location="my_details.html?"+ c.join(",") + "_"; 
0
source

It is better to use the replace () method to replace %20 with space

list.replace("%20"," ");

0
source

Source: https://habr.com/ru/post/904062/


All Articles