質問

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