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


- addEventListener 在 IE 11 中不起作用 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01