我有一个用 Google Closure 编译器编译的 Javascript 文件,它给了我这个错误TypeError: f is undefined
。当我查看编译后的代码时,无法理解,但其中的一部分已被注释掉。我真的很困惑为什么会收到此错误,但我怀疑它与以下脚本有关(这是我收到此错误后唯一编辑的内容)。
var response;
var request = new goog.net.XhrIo();
goog.events.listen(request, "complete", function(){
if (request.isSuccess()) {
response = request.getResponseText();
console.log("Satus code: ", request.getStatus(), " - ", request.getStatusText());
} else {
console.log(
"Something went wrong in the ajax call. Error code: ", request.getLastErrorCode(),
" - message: ", request.getLastError()
);
}
});
request.send("load_vocab.php");
var rawVocab = response[rawVocab];
var optionVocab = response[optionVocab];
alert(rawVocab.length);
alert(optionVocab.length);
这里还有 load_vocab.php ......
try {
$conn = new PDO('mysql:host=localhost;dbname=tygrif_school', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('SELECT word, translation, example_sentence_1 FROM vocabulary_game WHERE game_type = :game_type');
$stmt->execute(array('game_type' => 'target'));
while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$data['rawVocab'][] = $row;
}
$stmt = $conn->prepare('SELECT word, translation FROM vocabulary_game');
$stmt->execute(array());
while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$data['optionVocab'][] = $row;
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
echo json_encode($data);