tags:

views:

42

answers:

2

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>
+2  A: 

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.

patrick dw
Thank you patrick dw , it works .
web lover
@user - You're welcome. :o)
patrick dw
@web - `escape()` will work for your example, but if you're going to use a method call to accomplish it, you might as well use `encodeURI()`, as that is what it is meant to do.
patrick dw
A: 

You can "encodeURIComponent" your url:

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

Javascript encodeURIComponent method is equivalent to URLEncode.

Marc Uberstein
web lover
Thanks! Most people forget about escape() and it's such a handy method for front-end dev.
Marc Uberstein
**Never** use `escape()`. It is a JavaScript-only non-standard encoding scheme that is not the same as URL-encoding. Use `encodeURIComponent()` in preference, or `encodeURI()` in this case to encode only completely invalid characters like spaces.
bobince
I agree, I never checked if there were other encoders in javascript. Nice one! See: http://xkr.us/articles/javascript/encode-compare/
Marc Uberstein