I have a search input box and I am appending its data to an URL after the "#", e.g http://test.cl.com/#pqr xyz (using hash to avoid reloading of page). It is working fine but my data is not encoded as space is not replaced with + or %20 So before appending I am using the encodeURI function and then appending that value to the URL but still in the address bar there is the space character. Before assigning I have checked that I am appending the correct value (by alerting prq%20xyz).
Current output: http://test.cl.com/#pqr xyz
Required output : http://test.cl.com/#pqr+xyz
Please help me to find out the cause of the prob. Thanks!
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="jquery1.6.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#btn').click(function(){
var url = encodeURI("pqr xyz");
alert(url); // shows encoded value
window.location.hash = (url);
});
});
</script>
</head>
<body>
<h3>sample app</h3>
<button id="btn">
append
</button>
</body>