[英]Uncaught SyntaxError: Unexpected token ILLEGAL (PHP & Javascript)
I've looked a bit into this error and it seems that a majority of people with a similar question end up being the victim of invisible characters. 我已经研究了这个错误,似乎大多数有类似问题的人最终都是看不见的字符的受害者。 However, I've taken out any white space and retyped the code by hand and I'm still getting this error. 但是,我取出了所有空格,然后手动重新键入了代码,但仍然出现此错误。
I have singled the precise bit that induces the error, code below. 我已经选出了引起错误的精确位,下面的代码。
PHP PHP
printf("<td><button class=\"btn btn-primary btn-mini\" onclick=\"viewservice(%s)\">View</button></td>",$RadAcct_List_Obj->User_List[$i]['USERNAME']);
Javascript 使用Javascript
function viewservice(n)
{
alert(n);
}
This results in the Uncaught SyntaxError. 这将导致Uncaught SyntaxError。 However, if I remove the %s placeholder and the call at the end, and leave it as just this 但是,如果我最后删除了%s占位符和调用,并将其保留为原样
printf("<td><button class=\"btn btn-primary btn-mini\" onclick=\"viewservice()\">View</button></td>");
Then it works fine. 然后工作正常。 I don't understand why it's failing here, a few lines above this I am using similar code (below) and it's working fine. 我不明白为什么它在这里失败,在此之上的几行我正在使用类似的代码(如下),并且工作正常。
printf("<td>%s</td>",$RadAcct_List_Obj->User_List[$i]['USERNAME']);
You need quotes around your string literal in the JS: 您需要在JS中的字符串文字周围加上引号:
printf("<td><button class=\"btn btn-primary btn-mini\" onclick=\"viewservice('%s') ... etc
^ ^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.