Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript获取包含所有字符的查询字符串参数_Javascript_Query String - Fatal编程技术网

使用javascript获取包含所有字符的查询字符串参数

使用javascript获取包含所有字符的查询字符串参数,javascript,query-string,Javascript,Query String,我需要按名称获取查询字符串参数 我的参数包括所有类型的字符,包括“=”符号 以下是一个例子: 我试过: function getParameterByName(name) { var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search); return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); }

我需要按名称获取查询字符串参数

我的参数包括所有类型的字符,包括“=”符号

以下是一个例子:

我试过:

function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
function getParameterByName(key) {
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[key];
}
但它将“+”符号替换为空格:

“代码”:“Ippr7HP/Fad2q3kKMehQtVYnbFcZp h4ECS RCQmN KrcAM8N4tdeNciNEXlwkhnjF3tZgez1/A1CA1018UXPodGenPCYTJZSUPJSFUSMYUS1HORXY04WKLGIYW031 LAYXLDGHGJO 0S7SUD7LWFMAP8B3EN//YCBEQNM6RVC7AHMS77NG6I6P6MSCBEFU/RNJ5LY7TQW==

我试过:

function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
function getParameterByName(key) {
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[key];
}
函数getParameterByName(键){
var vars=[],散列;
var hashes=window.location.href.slice(window.location.href.indexOf('?')+1).split('&');
for(var i=0;i
但这不包括“=”符号


有什么建议吗?

您的第二次尝试已经足够接近了,您只需要在
之后重新加入值部分。拆分('=')

函数getParameterByName(parameterName){ var query=window.location.search.substring(1); var queryParameters={}; var vars=query.split('&'); 对于(变量i=0;i
所以…基本上…您的查询字符串格式不正确。如何修复生成它的内容,而不是尝试破解错误?@Quentin这就是asp.net identity生成代码以重置密码的方式,我不是自己编写的,也不想尝试更改他们的系统。非常感谢,这很有效ed完美!!只有一件事,我得到了一个错误:“查询未定义”,所以我将其替换为:
var vars=window.location.href.slice(window.location.href.indexOf('?')+1)。拆分('&');
还有更短的方法吗?非常感谢!