Jquery "load" for the path contains spaces - need help!

Now I work in a file manager that will be used in my simple cms, and I have a problem in the jquery download function when it takes a path containing spaces. is there any way to overcome this problem?

<script src="jquery.js"></script> <script> function get_content(){ $("#content").load("uploads/flashes/New folder/target.php") ; } </script> <div id="content"></div> 
+6
jquery load
source share
2 answers

You can "encode uricomponent" your url:

 $("#content").load(encodeURIComponent("uploads/flashes/New folder/target.php")); 

Javascript encodeURIComponent method is equivalent to URLEncode.

+17
source share

You can use %20 to represent a space.

 $("#content").load("uploads/flashes/New%20folder/target.php"); 

http://www.w3schools.com/TAGS/ref_urlencode.asp


EDIT:

If you do not want to do this manually, you can use encodeURI() instead . There are many common URI characters that it does not encode which escape() will be.

+5
source share

All Articles