Sambatyon
Sambatyon

Reputation: 3374

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\\FILE.EXT/some/other/params

however, XMLHttpRequest changes the address to:

http://myaddress:myport/action/C://PATH//TO//MY//FILE.EXT/some/other/params

which breaks the application. How can I prevent XMLHttpRequest from changing the requested address?

Upvotes: 1

Views: 821

Answers (2)

Ry-
Ry-

Reputation: 225054

Escape the path before putting it into your URL:

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

Upvotes: 1

Quentin
Quentin

Reputation: 943996

Don't put raw special characters in the URL.

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

Upvotes: 2

Related Questions