如何使用JavaScript安全地对URL进行编码,以便将其放入GET字符串?
var myUrl = "http://example.com/index.html?param=1&anotherParam=2";
var myOtherUrl = "http://example.com/index.html?url=" + myUrl;
Run Code Online (Sandbox Code Playgroud)
我假设你需要myUrl在第二行编码变量?
您是否知道将Javascript对象编码为string可以通过GET请求传递的快速而简单的方法?
不jQuery,没有其他框架 - 只是简单的Javascript :)
有没有办法在JavaScript中创建用于执行GET请求的查询参数?
就像在Python中一样urllib.urlencode(),它接收字典(或两个元组的列表)并创建一个类似的字符串'var1=value1&var2=value2'.