简体   繁体   English

无法发送带有#in参数的Ajax请求

[英]not able to send Ajax request with # in parameters

I am trying to send ajax request. 我正在尝试发送ajax请求。 following is the code 以下是代码

var parameters = '?dbSid='+dbSid+ '&dbPort='+dbPort+ '&dbIpAddress='+dbIpAddress+    '&dbUserName='+dbUserName+ '&dbPassword='+dbPassword;

new Ajax.Request('../pages/invoke-oracletestAgentCred.jsp'+parameters,   {onSuccess:successFunction , onFailure:errorFunction });  

If I send dbPassword as abcd then it works fine. 如果我将dbPassword作为abcd发送,则可以正常工作。

But when i send dbPassword as #abc it fails and sets the dbPassword to blank. 但是,当我将dbPassword发送为#abc时,它将失败并将dbPassword设置为空白。

Please help to solve the issue. 请帮助解决问题。

Thanks, Anjali 谢谢,安贾利

The # character has special meaning in URLs (it indicates the start of the document fragment). #字符在URL中具有特殊含义(它指示文档片段的开始)。

Make sure you encode your URL components (with encodeURIComponent ). 确保对URL组件进行编码(使用encodeURIComponent )。

Have you tried using encodeUriComponent? 您是否尝试过使用encodeUriComponent?

var parameters = '?dbSid='+encodeUriComponent(dbSid)+ '&dbPort='+encodeURIComponent(dbPort)+ '&dbIpAddress='+encodeURIComponent(dbIpAddress)+ '&dbUserName='+encodeURIComponent(dbUserName)+ '&dbPassword='+encodeURIComponent(dbPassword);

new Ajax.Request('../pages/invoke-oracletestAgentCred.jsp'+parameters, {onSuccess:successFunction , onFailure:errorFunction });

The reason a # breaks your url is that a # is used to go to a anchor in a page. #破坏您的网址的原因是#被用于转到页面的锚点。 That's why a browser will cut off any url at an #. 这就是为什么浏览器将在#处截断任何URL的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM