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
Add a ment  | 

2 Answers 2

Reset to default 9

The 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