admin管理员组文章数量:1277886
When I pass a file path, such as 'C:\u01\oracle\fmw_11114\data\proj\folder\name 09022014.txt
, from java controller to a javascript script, it causes the error 'Expected hexadecimal Digit
'.
This path is read from file-system and passed to the script directly and I can not escape the backslash '\' in the string before passing it to the script. Any ideas how to solve the problem?
if(document.getElementById('hdnA').value == 'ALR') {
alert('ERROR: ' + '${arch}' + ' file not found.')
}
When I pass a file path, such as 'C:\u01\oracle\fmw_11114\data\proj\folder\name 09022014.txt
, from java controller to a javascript script, it causes the error 'Expected hexadecimal Digit
'.
This path is read from file-system and passed to the script directly and I can not escape the backslash '\' in the string before passing it to the script. Any ideas how to solve the problem?
if(document.getElementById('hdnA').value == 'ALR') {
alert('ERROR: ' + '${arch}' + ' file not found.')
}
Share
Improve this question
edited Sep 16, 2012 at 20:59
hekomobile
asked Sep 16, 2012 at 20:51
hekomobilehekomobile
1,3881 gold badge14 silver badges35 bronze badges
1
- passed to the script directly and I can not escape the backslash Why? The path has to be written into the script section anywhere – Andreas Commented Sep 16, 2012 at 22:17
2 Answers
Reset to default 9The error message is a good indicator to what went wrong.
Unicode characters can be passed literally to a script using the format: \uXXXX (Where XXXX represent the code for the specific character).
Your path includes a folder whose name starts with U, so the path string contains the the literal control characters for literal Unicode character insertion (\u).
An easy workaround would be passing the file path with forward slashes instead:
'C:/u01/oracle/fmw_11114/data/proj/folder/name 09022014.txt'
I ran into the same issue with my Java application, which tried inserting a script dynamically with path values in the element. Changing my backslashes to forward slashes resolved the issue for me.
Salam! Use this regexp:
patt=/\\/g;
str = str.replace(patt,"\\\\")
this worked for me;
本文标签: javascriptexpected hexadecimal digitStack Overflow
版权声明:本文标题:javascript - expected hexadecimal digit - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741236971a2363209.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论