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中不起作用


基础教程推荐
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01