Skip to content Skip to sidebar Skip to footer

Xmlhttprequest Automatically Replaces Backslash (\) With Slash (/)

I am trying to run a small javascript script. one of the parameters of the XMLHttpRequest is a file path, so a URL would look like: http://myaddress:myport/action/C:\\PATH\\TO\\MY\

Solution 1:

Don't put raw special characters in the URL.

encodeURIComponent('C:\\PATH\\TO\\MY\\FILE.EXT')
"C%3A%5CPATH%5CTO%5CMY%5CFILE.EXT"

Solution 2:

Escape the path before putting it into your URL:

'http://myaddress:myport/action/' + encodeURIComponent('C:\\PATH\\TO\\MY\\FILE.EXT') + '/some/other/params'

Post a Comment for "Xmlhttprequest Automatically Replaces Backslash (\) With Slash (/)"