简体   繁体   English

Uncaught SyntaxError:意外的令牌非法(PHP&Javascript)

[英]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.

相关问题 PHP Javascript Uncaught SyntaxError: Unexpected token ILLEGAL - PHP Javascript Uncaught SyntaxError: Unexpected token ILLEGAL Uncaught SyntaxError:意外的令牌非法-PHP和Javascript Zend Studio - Uncaught SyntaxError: Unexpected token ILLEGAL - PHP and Javascript Zend Studio Uncaught SyntaxError:意外的令牌非法—将PHP包含在JQuery / JavaScript中时 - Uncaught SyntaxError: Unexpected token ILLEGAL — When including PHP into JQuery/JavaScript PHP / jQuery未捕获的SyntaxError:意外的令牌非法 - PHP/jQuery Uncaught SyntaxError: Unexpected token ILLEGAL Uncaught SyntaxError:意外的令牌非法 - Uncaught SyntaxError: Unexpected token ILLEGAL 未捕获的SyntaxError Unexpected Token非法javascript与txt文件 - Uncaught SyntaxError Unexpected Token illegal javascript with txt file 未捕获的SyntaxError:意外的令牌ILLEGAL load-scripts.php:1 - Uncaught SyntaxError: Unexpected token ILLEGAL load-scripts.php:1 ExtJS / PHP / MySQL:未捕获的语法错误:意外的令牌非法 - ExtJS/PHP/MySQL: Uncaught SyntaxError: Unexpected token ILLEGAL jQuery Uncaught SyntaxError:意外的令牌非法 - jquery Uncaught SyntaxError: Unexpected token ILLEGAL Chrome浏览器检查器:未捕获的语法错误:意外的令牌非法 - Chrome Inspector: Uncaught SyntaxError: Unexpected token ILLEGAL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM