我正在使用 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中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
即使在调用 abort (jQuery) 之后,浏览器也会等待Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在调用 abort (jQuery) 之后,浏览器也会等待 ajax 调用
JavaScript innerHTML 不适用于 IE?JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不适用于 IE?)
XMLHttpRequest 无法加载,请求的资源上不存在“AXMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 无法加载,请求的资
XHR HEAD 请求是否有可能不遵循重定向 (301 302)Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 请求是否有可能不遵循重定向 (301 302))
NETWORK_ERROR:XMLHttpRequest 异常 101NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 异常 101)
XMLHttpRequest 206 部分内容XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分内容)