問題描述
我正在使用 AJAX 執(zhí)行 struts 操作,一切正常,但 Firefox 出現(xiàn)問題,當(dāng)我將 URL 中的參數(shù)作為請(qǐng)求參數(shù)傳遞時(shí),如果該參數(shù)最后包含哈希(#)符號(hào),那么firefox 會(huì)刪除該符號(hào)之后的所有內(nèi)容,并在沒有它的情況下將該參數(shù)發(fā)送到操作.
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,那么我在動(dòng)作類中只得到 test123,而不是 test123#abcd,這對(duì)我的要求來說是不可取的.對(duì)于 IE,它工作得很好.有什么辦法可以我可以提取完整的參數(shù),包括 Firefox 中的 # 符號(hào).
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.
如果我還需要發(fā)布 java 操作代碼,請(qǐng)告訴我,謝謝.
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);
這會(huì)將您的 valuePassword
編碼為有效的 URL 組件,該組件可以作為 URL 中的查詢字符串傳遞
This will encode your valuePassword
to a valid URL component which can be passed as a query string in URLs
另一方面,您應(yīng)該使用 decodeURIComponent
從編碼字符串中獲取值
And on the other side you should use decodeURIComponent
to get the value from encoded string
var value = decodeURIComponent(valuePasswordPassed);
要了解更多信息去這里
這篇關(guān)于傳遞“#"url的請(qǐng)求參數(shù)中的哈希符號(hào)在Firefox中不起作用的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!