恩codeuricomponent在轨对其进行解码 [英] Encodeuricomponent decoding it in rails

查看:163
本文介绍了恩codeuricomponent在轨对其进行解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常情况下轨神奇地去codeS均 PARAMS 。现在,我得到一个JavaScript这确实 PARAMS =值=+ EN codeURIComponent('AB#CD'); ,然后调用 HTTP ://服务器/控制器值= AB%23cd ?。如果我访问 PARAMS [:值] 在我的控制器,它包含 AB%23cd ,而不是 AB#CD 因为我期望的那样。

Normally rails magically decodes all params. Now I got a javascript which does params="value="+encodeURIComponent('ab#cd'); and then calls http://server/controller?value=ab%23cd. If I access params[:value] in my controller, it contains ab%23cd and not ab#cd as I would expect.

如何解决此问题?为什么导轨这个参数没有自动解码?

How to solve this? Why does rails no auto decoding of this param?

推荐答案

Rails的自动的处理参数与以下逻辑。

Rails "automagically" handles parameters with the following logic.

如果请求的是得到它会去查询字符串code什么:

If the request is GET it will decode anything in the query string:

GET http://server/controller?value=ab%23cd
  On the server this will generate params['value'] as ab#cd

如果该请求是一个查询字符串POST它将C中,它不会去$ C $:

If the request is a POST with a query string it will not decode it:

POST http://server/controller?value=ab%23cd
  On the server this will generate params['value'] as ab%23cd

如果该请求是数据参数的POST,它会去code的:

If the request is a POST with data parameters, it will decode it:

POST http://server/controller
  data: value=ab%23cd
  On the server this will generate params['value'] as ab#cd

我怀疑你所看到的,因为你包括与 POST 的要求,而不是一个查询字符串,这个问题 GET 要求等Rails是不是查询字符串解码。

I suspect that you're seeing this issue because you're including a query string with a POST request instead of a GET request and so Rails isn't decoding the query string.

这篇关于恩codeuricomponent在轨对其进行解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆