XMLHttpRequest 自动用斜杠 (/) 替换反斜杠 (\) [英] XMLHttpRequest automatically replaces backslash (\) with slash (/)
本文介绍了XMLHttpRequest 自动用斜杠 (/) 替换反斜杠 (\)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试运行一个小的 JavaScript 脚本.XMLHttpRequest 的参数之一是文件路径,因此 URL 如下所示:
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
然而,XMLHttpRequest 将地址更改为:
however, XMLHttpRequest changes the address to:
http://myaddress:myport/action/C://PATH//TO//MY//FILE.EXT/some/other/params
这会破坏应用程序.如何防止 XMLHttpRequest 更改请求的地址?
which breaks the application. How can I prevent XMLHttpRequest from changing the requested address?
推荐答案
不要在 URL 中放置原始的特殊字符.
Don't put raw special characters in the URL.
encodeURIComponent('C:\\PATH\\TO\\MY\\FILE.EXT')
"C%3A%5CPATH%5CTO%5CMY%5CFILE.EXT"
这篇关于XMLHttpRequest 自动用斜杠 (/) 替换反斜杠 (\)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文