Passing quot;#quot; hash symbol in request parameter of url not working in Firefox(传递“#url的请求参数中的哈希符号在Firefox中不起作用)
问题描述
我正在使用 AJAX 执行 struts 操作,一切正常,但 Firefox 出现问题,当我将 URL 中的参数作为请求参数传递时,如果该参数最后包含哈希(#)符号,那么firefox 会删除该符号之后的所有内容,并在没有它的情况下将该参数发送到操作.
I am hitting a struts action using AJAX, everything is fine but there is problem with Firefox , when i am passing the parameter in URL as a request parameter and if that parameter, contains hash(#) symbol in the end, then firefox strips everything after that symbol and send that parameter to action without it.
例如,如果我在 Firefox 中通过了 test123#abcd,那么我在动作类中只得到 test123,而不是 test123#abcd,这对我的要求来说是不可取的.对于 IE,它工作得很好.有什么办法可以我可以提取完整的参数,包括 Firefox 中的 # 符号.
For example, if im passing test123#abcd in Firefox, then i am getting only test123 in action class as opposed to test123#abcd which is undesirable for my requirement.For IE it is working perfectly.Is there any way by which i can extract the full parameter including the # symbol in Firefox.
如果我还需要发布 java 操作代码,请告诉我,谢谢.
please let me know if i need to post the java action code also,thanks.
JS 片段
var valuePassword=test123#abcd;
var url = "/test/ChangePwdAjax.do?newPass="+valuePassword;
var xmlHTTP = getXMLHTTPRequest();
推荐答案
使用
var url = "/test/ChangePwdAjax.do?newPass="+ encodeURIComponent(valuePassword);
这会将您的 valuePassword
编码为有效的 URL 组件,该组件可以作为 URL 中的查询字符串传递
This will encode your valuePassword
to a valid URL component which can be passed as a query string in URLs
另一方面,您应该使用 decodeURIComponent
从编码字符串中获取值
And on the other side you should use decodeURIComponent
to get the value from encoded string
var value = decodeURIComponent(valuePasswordPassed);
要了解更多信息去这里
这篇关于传递“#"url的请求参数中的哈希符号在Firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:传递“#"url的请求参数中的哈希符号在Firefox中不起作用


基础教程推荐
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01