使用Javascript,我想生成一个页面的链接.页面的参数位于我在JSON中序列化的Javascript数组中.
所以我想生成一个这样的URL:
http://example.com/?data="MY_JSON_ARRAY_HERE"
Run Code Online (Sandbox Code Playgroud)
如何转义我的JSON字符串(数组序列化)以将其作为URL中的参数包含?
如果有一个使用JQuery的解决方案,我会喜欢它.
注意:是的,页面的参数需要在一个数组中,因为它们有很多.我想我会用bit.ly来缩短之后的链接.
我在chrome扩展(内容脚本)中发出JSONP请求.当我作为网页运行 - 在我的浏览器中加载HTML文件时,一切都运行良好,但是当我将其作为chrome扩展加载时,当服务器给出响应时,jquery创建的jsonp回调函数似乎不存在.
我的控制台说:
Uncaught ReferenceError: jQuery17105683612572029233_1323808231542 is not defined
Run Code Online (Sandbox Code Playgroud)
这是我的ajax请求:
$.ajax({
url: 'http://example.com',
data:
{
imgUrl: this.href,
returnString:true
},
dataType: "jsonp",
success: function(msg){
newNode.src = msg.data;
},
error: function(msg){
console.log(msg.data);
}
})
Run Code Online (Sandbox Code Playgroud)