Database 与LimeJS中的DB通信
从DB将变量加载到游戏中的正确方法是什么 我试着使用Ajax和原型库,但这似乎不起作用。以下是我所做的: 在我的主.js游戏文件中Database 与LimeJS中的DB通信,database,limejs,Database,Limejs,从DB将变量加载到游戏中的正确方法是什么 我试着使用Ajax和原型库,但这似乎不起作用。以下是我所做的: 在我的主.js游戏文件中 var rawVocab = new Array(); var optionVocab = new Array(); new Ajax.Request('load_vocab.php', { onSuccess : function(xmlhttp) { eval(xmlhttp.responseText); } }); “loa
var rawVocab = new Array();
var optionVocab = new Array();
new Ajax.Request('load_vocab.php', {
onSuccess : function(xmlhttp) {
eval(xmlhttp.responseText);
}
});
“load_vocab.php”看起来像这样
<?php
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';
echo '<response>';
$username = "user";
$password = "***************";
try {
$conn = new PDO('mysql:host=localhost;dbname=tygrif_school', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('SELECT * FROM vocabulary_game WHERE game_type = :game_type');
$stmt->execute(array('game_type' => 'target'));
$i=0;
while($row = $stmt->fetch()) {
echo "rawVocab[".$i."]['word']='".$row['word']."';";
echo "rawVocab[".$i."]['translation']='".$row['translation']."';";
echo "rawVocab[".$i."]['example_sentence_1']='".$row['example_sentence_1']."';";
$i++;
}
$stmt = $conn->prepare('SELECT * FROM vocabulary_game');
$stmt->execute(array());
$i=0;
while($row = $stmt->fetch()) {
echo "optionVocab[".$i."]['word']='".$row['word']."';";
echo "optionVocab[".$i."]['translation']='".$row['translation']."';";
echo "optionVocab[".$i."]['example_sentence_1']='".$row['example_sentence_1']."';";
$i++;
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
echo '</response>';
?>
“target”);
$i=0;
而($row=$stmt->fetch()){
echo“rawVocab[”$i.“][word']='”“$row['word'].”“;”;
echo“rawVocab[“$i.”]['translation']='”“$row['translation'].”“;”;
回显“rawVocab[“$i.”][“示例句子[u 1']=””。“$row[“示例句子[u 1']”。”;”;
$i++;
}
$stmt=$conn->prepare('SELECT*FROM词汇表\游戏');
$stmt->execute(array());
$i=0;
而($row=$stmt->fetch()){
echo“optionVocab[”$i.“]['word']='”““$row['word'].”“;”;
echo“optionVocab[“$i.”]['translation']='”“$row['translation'].”“;”;
echo“optionVocab[“$i.”]['example_Session_1']='”“$row['example_Session_1'].”“;”;
$i++;
}
}捕获(PDO$e){
回显“错误:”。$e->getMessage();
}
回声';
?>
goog库是否有一些内置的方法来处理这个问题?显然,Google Closure有一种内置的方法(goog.net.XhrIo)来处理Ajax调用 1- 2-