在请求参数中传递“#”哈希符号,而不是在Firefox中工作。

时间:2022-12-06 19:30:53

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.

我触及struts动作使用AJAX,一切都很好但是Firefox有问题,当我在URL作为请求参数传递的参数,如果参数,包含哈希(#)最后,象征之后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.

例如,如果我在Firefox中传递test123#abcd,那么我在action类中只能得到test123#abcd,而test123#abcd不符合我的要求。因为IE运行得很好。有什么方法可以提取完整的参数,包括Firefox中的#符号。

please let me know if i need to post the java action code also,thanks.

如果我也需要发布java动作代码,请告诉我,谢谢。

JS snippet

JS代码片段

var valuePassword=test123#abcd;

    var url = "/test/ChangePwdAjax.do?newPass="+valuePassword;
            var xmlHTTP = getXMLHTTPRequest();

2 个解决方案

#1


11  

Use

使用

var url = "/test/ChangePwdAjax.do?newPass="+ encodeURIComponent(valuePassword);

This will encode your valuePassword to a valid URL component which can be passed as a query string in URLs

这将把valuePassword编码为一个有效的URL组件,该组件可以作为URL中的查询字符串传递

And on the other side you should use decodeURIComponent to get the value from encoded string

另一方面,你应该使用decodeURIComponent从编码的字符串中获取值。

var value = decodeURIComponent(valuePasswordPassed);

To know more about this Go here

要了解更多,请到这里

#2


1  

When you change data you have to do a http POST request. Not a GET request. This will automatically solve your problem without having to encode your password.

当您更改数据时,您必须执行http POST请求。不是一个GET请求。这将自动解决您的问题,而无需编码您的密码。

xmlhttp.open("POST", "/test/ChangePwdAjax.do", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("newPass=" + valuePassword);

#1


11  

Use

使用

var url = "/test/ChangePwdAjax.do?newPass="+ encodeURIComponent(valuePassword);

This will encode your valuePassword to a valid URL component which can be passed as a query string in URLs

这将把valuePassword编码为一个有效的URL组件,该组件可以作为URL中的查询字符串传递

And on the other side you should use decodeURIComponent to get the value from encoded string

另一方面,你应该使用decodeURIComponent从编码的字符串中获取值。

var value = decodeURIComponent(valuePasswordPassed);

To know more about this Go here

要了解更多,请到这里

#2


1  

When you change data you have to do a http POST request. Not a GET request. This will automatically solve your problem without having to encode your password.

当您更改数据时,您必须执行http POST请求。不是一个GET请求。这将自动解决您的问题,而无需编码您的密码。

xmlhttp.open("POST", "/test/ChangePwdAjax.do", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("newPass=" + valuePassword);