我正在使用以下函数使我能够轻松地从 URL 中获取查询字符串。
var urlParams = {};
(function () {
var e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
q = window.location.search.substring(1);
while (e = r.exec(q))
urlParams[d(e[1])] = d(e[2]);
})();
然后我简单地打电话
var k=urlParams["url"];
var ttl=urlParams["title"];
这一直很好,除了以下查询字符串破坏了函数:
?title=Jpreay%20will%20do%20a%20press%20release%20or%20news%20announcement%20commercial%20for%20$5,%20only%20on%20fiverr.com&cnt=For%20only%205$,%20jpreay%20will%20do%20a%20press%20release%20or%20news%20announcement%20commercial.%20Top%20Rated%20Seller%20100%%20Rating%20for%20Over%2010%20Months%20Now%20In%20this%20gig%20I%20am%20providing%20a%20news%20release%20or%20some%20other%20type%20of%20event%20|%20On%20Fiverr.com&url=http%3A%2F%2Ffiverr.com%2Fjpreay%2Ffilm-a-press-release-or-news-announcement-of-your-product-or-services
我收到以下错误:
URIError: malformed URI sequence
[Break On This Error]
var k=urlParams["url"];
谁能帮我弄清楚这里的问题是什么?
提前致谢!