Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

javascript - SyntaxError: identifier starts immediately after numeric literal in Firebug

I'm getting that error when I call this javascript function:

function kickUser(id_userChat){
$.post("chatFuncs.php", { action: "kick", id_user: id_userChat });  
}

this "kickUser" function is generated for every user connected to my chat box, like this

$listUsers .= '<img src="imgUsers/'.$DBClass->nomImg($rowUsers['id_user'],$posImg).'" height="'.$heightImg.'" width="'.$widhImg.'"/>
<span class="styleMsg">'.$rowUser['nameUser'].'</span>&nbsp;
<a href="#" class="BtnKick" onClick="kickUser('.$rowUsers['id_user'].')">Kick</a></br>';

and the action "kick" is just an update to my database where I remove the user from my chatUsers table

If I change $rowUsers['id_user'] for $rowUsers['userName'] the error changes to: ReferenceError: 'userName' is not defined (i changed the real name of the user for 'userName' just for this example).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Identifiers in JavaScript can't begin with a number; they must begin with a letter, $ or _.


I'm guessing it's coming from this:

onclick="kick_user('.$rowUsers['id_user'].')">Kick</a>

If you mean to pass a string, then you need to quote the value being passed.

onclick="kick_user("'.$rowUsers['id_user'].'")">Kick</a>

I don't know PHP, so maybe you need different escaping, but this should give you the idea.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...