admin管理员组文章数量:1432001
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.
本文标签: Javascript Weird illegal character error on a if statementStack Overflow
版权声明:本文标题:Javascript: Weird illegal character error on a if statement - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745480590a2660154.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论