• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with sending # character through ajax

 
darshan karle
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello every body

i am trying to send #20 number using AJAX and displaying names based on the number.But my problem is it not received in the server side. if i send as 20 then it is recieved. please help out in this. i am placing the code below



<script type="text/javascript">
var xmlHttp

function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="get1.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>



<body>
<form>
Number:
<input type="text" id="txt1" onkeyup="showHint(this.value)">
</form>

Suggestions: <span id="txtHint"></span>


</body>


regards
darshan
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
darshan karle wrote:hello every body

i am trying to send #20 number using AJAX


The '#' symbol ('pound' symbol) have special meaning in URL, its is used to indicate where a fragment identifier (bookmarks/anchors in HTML) begins in URL.

So avoid it, but if you still want to use it, then encoded it with '%' symbol concatenated by its hex(23) value, then URL looks like,,

http://mysite.com/app/servlet?param=%23

'%23' is for '#'.

More information can be found here.
 
darshan karle
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks rohan for the help

regards
darshan
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
darshan karle wrote:thanks rohan for the help


You're welcome . And my name is Sagar, 'rohan' is part of my surname.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be using encodeURIComponent: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/encodeURIComponent

Eric
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic