Showing posts with label encodeURIComponent. Show all posts
Showing posts with label encodeURIComponent. Show all posts

Saturday, May 04, 2013

How to encode a URL in JavaScript



encodeURI() function is used to encode a URI.

var encode_favourite= encodeURIComponent(favourite);

You have three options:

    escape() will not encode: @*/+

    encodeURI() will not encode: ~!@#$&*()=:/,;?+'

    encodeURIComponent() will not encode: ~!*()'

if you want to pass a URL into a GET parameter of other page, you should use escape or encodeURIComponent, but not encodeURI.

Example : 
<script>
var uri="my test.php?name=stale&car=lenova";
document.write(encodeURI(uri)+ "<br>");
</script> 


Tip: Use the decodeURI() function to decode an encoded URI.

Monday, April 15, 2013

Controlling access with .htaccess | On form submit to change url in php


Once you submit the button , the url  will change with your search word.  And you encode the url in java-script and add your additional parameters. 


<script>
var url_v      =   $('#searchform').attr("action");
var parameters =   $("#searchingchart").val();
parameters_v   = encodeURIComponent(parameters);
url_v          = url_v + parameters_v   ;
$('#searchform').attr("action",url_v);
</script>

 <form name="form" method="post"  action="/products/"  id="searchform">
 <input type="text"  name="search_val" id="searchingchart" value=""/>
 <input type="submit" id="submit" value="Search"/>
 </form>

In your website url with .(point), you get 404 error . On that time we control the url in .htaccess.

Paste this code in .htacess to get the url has workable.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]


Example URL:
http://www.yoursite.com/products/Max. volume