将参数从 swfupload/uploadify 传递到 Rails 应用程序 - 损坏了吗?
我有一个 uploadify 组件,它将文件发送回 Rails 应用程序。我在某些时候注意到的问题是,对于某些特殊值,传递的数据会被闪存对象更改。
在客户端,我有
$(document).ready(function() {
$('#photo_image').uploadify({
...
'scriptData': {
authenticity_token = 'M++Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro='
...
}
});
});
Rails 得到的结果:
"authenticity_token"=>"M Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro="
当令牌中没有“+”符号时,一切正常。看起来闪光灯正在以某种方式改变字符串。知道如何逃脱吗?我尝试了 CGI.escape,但结果完全相同,“+”被删除......
I have an uploadify component, which sends the files back to rails application. The problem I noticed at some point is, that for some special values data passed along are altered by the flash object.
On the client side I have
$(document).ready(function() {
$('#photo_image').uploadify({
...
'scriptData': {
authenticity_token = 'M++Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro='
...
}
});
});
What Rails is getting:
"authenticity_token"=>"M Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro="
When there is no '+' sign in the token everything works just fine. It looks like the flash is altering the string somehow. Any idea how to escape it? I tried CGI.escape, but result is exactly the same, '+' are stripped...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须使用encodeURIComponent()来编码特殊字符:
You have to use encodeURIComponent() to encode special characters:
实际的解决方案是,对令牌进行两次转义。例如“encodeURIComponent(encodeURIComponent(token)))”或#{uu token}。
Actual solution is, to escape the token twice. So for example "encodeURIComponent(encodeURIComponent(token)))" or #{u u token}.