I am making an AJAX chat room with the manual of an AJAX book in which I participate in using the JSON and eval () functions. This chat has a regular chat function and a whiteboard function. When a normal text message comes from a php server in JSON format, javascript in the browser does this:
Without Whiteboard Command -------------------------------------------
function importServerNewMessagesSince(msgid) {
var latest = loadText("get_messages_since.php?message=" + msgid);
var msgs = eval(latest);
for (var i = 0; i < msgs.length; i++) {
var msg = msgs[i];
displayMessage(escape(msg.id), escape(msg.author), escape(msg.contents));
} ...
Board drawing commands are sent by the server in JSON format with a special username called "SVR_CMD", now javascript has been slightly changed:
With Whiteboard Team -------------------------------------------- --- ---
function importServerNewMessagesSince(msgid) {
var latest = loadText("get_messages_since.php?message=" + msgid);
var msgs = eval(latest);
for (var i = 0; i < msgs.length; i++) {
var msg = msgs[i];
if (msg.author == "SVR_CMD") {
eval(msg.contents);
else {
displayMessage(escape(msg.id), escape(msg.author), escape(msg.contents));
}
} ...
, SVR_CMD script, javascript, insdead drawLine (200,345,222,333), redirectToMyVirusSite(). eval() .
, , eval , , . , , , . JSON ?
. php .net javascriptencode/escape, , JavaScript , eval()? JSON eval() , , ?
,