You do know that xhr requests are asynchronous?
This means that when you call send you have to wait for the response to return, what you do is try to read the response on the next line. Your quoting is a problem too, the compiler will rename rawVocab and optionVocab but the returned data will not be renamed so you need to quote these values as ne8il pointed out.
var response;
var request = new goog.net.XhrIo();
goog.events.listen(request, "complete", function(){
if (request.isSuccess()) {
window['console'].log("Now the response returned, setting response variable");
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()
);
}
});
window['console'].log("Sending request");
request.send("load_vocab.php");
window['console'].log("Trying to read response");
var rawVocab = response['rawVocab'];
var optionVocab = response['optionVocab'];
The output of the above code would be:
Sending request
Trying to read response
Error
Now the response returned, setting response variable