Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery "load" for path contain spaces - Need help !

Tags:

jquery

load

I'm working now in a file manager to be used in my simple cms and I have a problem in jquery load function when it takes a path contain 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>
like image 323
web lover Avatar asked Sep 18 '10 12:09

web lover


3 Answers

You can "encodeURIComponent" your url:

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

Javascript encodeURIComponent method is equivalent to URLEncode.

like image 162
Marc Uberstein Avatar answered Oct 25 '22 11:10

Marc Uberstein


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 don't want to do it manually, you could use encodeURI() instead. There are a number of common URI characters that it does not encode, which escape() will.

like image 39
user113716 Avatar answered Oct 25 '22 10:10

user113716


From the above answers, encodeURI() has worked fine with me. On the other hand, encodeURIComponent() has changed also the representation for the '/' character, with the result of not doing properly the HTTP request to the desired URL. So, I recommend to use the encodeURI() solution in the case that the path String includes '/'.

like image 28
JoM Avatar answered Oct 25 '22 10:10

JoM