I have some Ajax that gets info from a database and stores it in an array called targetVocab
. This info is used to set the value of vocab
when setVocab() is called. This works fine the first time, but when the play again button is hit and setVocab is called a second time, it doesn't work. The second time it appears that targetVocab is empty. This is my simplified script...
var targetVocab;
var vocab;
var request = new goog.net.XhrIo();
goog.events.listen(request, "complete", function(){
if (request.isSuccess()) {
response = request.getResponseJson();
targetVocab = response['targetVocab'];
setVocab(targetVocab);
}
});
request.send("load_vocab.php");
var setVocab = function(targetVocab) {
vocab = targetVocab;
}
var getVocab = function() {
return vocab;
}
goog.events.listen(playAgainButton, ['mousedown', 'touchstart'], function(e) {
getVocab();
});
UPDATE:
I've come to realize that whatever I do to vocab
is similarly applied to targetVocab
. My original idea was that I could splice elements from vocab
throughout the app and then reset vocab
to it's original state by setting it again to targetVocab
. Is there some way to set vocab
equal to targetVocab
without the two remaining connected in this way?