I'm trying to write a jquery interface which requires me to pass a couple of parameters to our CMS. These parameters are in the form "attribute[n]:token" so in a URL you'd end up with "...&attribute[1]:value=hello_world...". Unfortunately when I try to use a $.get to pass this data it chok开发者_运维问答es for fairly obvious reasons. I'm tried the methods I can think of to escape these character and and I'm sure I'm missing a simple trick but I can't come up with a method which works. I hope this isn't as simple a question as it sounds.
example code:
$.get("/example.htm",
{
Attributes[1]:type: "option",
Attributes[1]:value: "large"
});
many thanks in advance, Sam
you can use the javascript function encodeURI():
var params = {};
params[encodeURI('Attributes[1]:type')] = 'option';
params[encodeURI('Attributes[1]:value')] = 'large';
$.get("/example.htm", params);
You could always try adding quotes around the keys
$.get("/example.htm",
{
"Attributes[1]:type": "option",
"Attributes[1]:value": "large"
});
精彩评论