I've been struggling with a strange syntax error since yesterday: The FF debugger keeps saying "SyntaxError: illegal character" at this specific line :
function newTimePeriod(ID, param, paramID, unit)
{
updateSession();
//check if date
//(I got this regex from another post)
var re = new RegExp("^\\d{4,4}(-\\d{1,2}){1,2}( \\d{1,2}(:\\d{1,2}){1,2})?$");
var dateFrom = document.getElementById("chart_date_min_" + ID).value;
var dateTo = document.getElementById("chart_date_max_" + ID).value;
var fromCorrect = re.test(dateFrom);
var toCorrect = re.test(dateFrom);
/**/if (fromCorrect && toCorrect){/**/ //return illegal character
LoadGraph(ID, param, paramID, unit, dateFrom, dateTo);
}
}
I tried to include this script into the main php page, or separate it; it doesn't change a thing. Charset used is UTF-8, and fromCorrect and toCorrect returns booleans correctly (the regex is working)
When I remove the if statement the script is loading... Notepad++ doesn't show any special characters hiding anywhere.
Any thoughts?
I've been struggling with a strange syntax error since yesterday: The FF debugger keeps saying "SyntaxError: illegal character" at this specific line :
function newTimePeriod(ID, param, paramID, unit)
{
updateSession();
//check if date
//(I got this regex from another post)
var re = new RegExp("^\\d{4,4}(-\\d{1,2}){1,2}( \\d{1,2}(:\\d{1,2}){1,2})?$");
var dateFrom = document.getElementById("chart_date_min_" + ID).value;
var dateTo = document.getElementById("chart_date_max_" + ID).value;
var fromCorrect = re.test(dateFrom);
var toCorrect = re.test(dateFrom);
/**/if (fromCorrect && toCorrect){/**/ //return illegal character
LoadGraph(ID, param, paramID, unit, dateFrom, dateTo);
}
}
I tried to include this script into the main php page, or separate it; it doesn't change a thing. Charset used is UTF-8, and fromCorrect and toCorrect returns booleans correctly (the regex is working)
When I remove the if statement the script is loading... Notepad++ doesn't show any special characters hiding anywhere.
Any thoughts?
Share Improve this question edited Dec 21, 2013 at 13:27 Bathsheba 235k35 gold badges374 silver badges501 bronze badges asked Dec 21, 2013 at 11:42 SciidSciid 391 silver badge10 bronze badges 5- I think/hope OP added the ** to show which line the error is in. – afaf12 Commented Dec 21, 2013 at 11:45
- Can you also provide the html for this specially dateFrom and dateTo – Raunak Kathuria Commented Dec 21, 2013 at 11:48
-
There is an invisible space between
)
and{
. Delete the line and re-write it (don't copy-paste). – JJJ Commented Dec 21, 2013 at 11:53 - possible duplicate of SyntaxError: Unexpected token ILLEGAL – JJJ Commented Dec 21, 2013 at 11:54
- If you are interested in what non-printable character caused the error, then you could copy the line in question into a HEX editor. The HEX view of (g)vim is quite helpful for those kinds of problem. – Ralf Commented Dec 21, 2013 at 12:21
2 Answers
Reset to default 5I have copied your code into a fiddle - seems you have a zero-width space between the braces:
if (fromCorrect && toCorrect){
^
The good way to solve weird characters creeping in from copying and pasting is to manually re-type the line in question.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745480590a4629538.html
评论列表(0条)