문제

Iam using query sting in jquery

to get URL values iam using

    function getUrlVars() {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
    hash = hashes[i].split('=');
    vars.push(hash[0]);
    vars[hash[0]] = hash[1];
}
return vars;

Here when i pass Query String to URL it is giving spaces as %20 and when i fectch value from URL iam getting vaue of name as Name%20Name format

What should i do in order to get name with space as seperation??

도움이 되었습니까?

해결책

You need the decodeURIComponent() Javascript function:

decodeURIComponent("Name%20Name") // "Name Name"

Decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent or by a similar routine.

For more information see the documentation.

다른 팁

Use the native Javascript function unescape, it is supported in all major browsers:

var a = "Name%20Name";
window.unescape(a);

You can turn any encoded urls to "normal" representation using decodeURIComponent();

function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(decodeURIComponent(hash[0]));
        vars[hash[0]] = hash[1];
    }
    return vars;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top