传递“#” url的请求参数中的哈希符号在Firefox中不起作用 [英] Passing "#" hash symbol in request parameter of url not working in Firefox

查看:90
本文介绍了传递“#” 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 class而不是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中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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