Simple XhrIo doesn't work because Logger is undefined.

58 views
Skip to first unread message

salbertson

unread,
Jan 29, 2010, 1:25:23 PM1/29/10
to Closure Library Discuss
I am trying to do a simple XhrIo request (as per website example):

var xhr = new goog.net.XhrIo();

goog.events.listen(xhr, goog.net.EventType.COMPLETE, function(e) {
obj = this.getResponseText();
console.info(obj);
});

xhr.send('blah.html');

But it's not working, errors show:
goog.debug.Logger is undefined

Doesn't the xhrio.js file include the logger?

Please help.

Larry Hosken

unread,
Jan 29, 2010, 9:53:20 PM1/29/10
to closure-lib...@googlegroups.com
Hmm... the compiler should pull in the logger code when you compile
your code. (I haven't tried this example, though, so there could be a
problem.)

Was there an error message or something when you compiled your code?
(I'm guessing the "goog.debug.Logger is undefined" message was at
runtime, not compile time... but I'm just guessing.)

-Larry H.

salbertson

unread,
Feb 1, 2010, 2:51:35 PM2/1/10
to Closure Library Discuss
I believe the problem was with my event listener callback. Here is
what I used and everything worked fine:

my.custom.nameSpace.doIt = function() {


var xhr = new goog.net.XhrIo();

var onTemplateLoad = goog.bind(this.loadTemplate, this);
goog.events.listen(xhr, goog.net.EventType.COMPLETE,
onTemplateLoad, true);
xhr.send('template.html');
};

my.custom.nameSpace.prototype.loadTemplate = function(e) {
var xhr = e.target;
iframeContent = '<!DOCTYPE html><html><head></head><body>' +
xhr.getResponseText() + '</body></html>';

// this.iframe_ was set in constructor
var doc = goog.dom.getFrameContentDocument(this.iframe_);
doc.open();
doc.write(iframeContent);
doc.close();
};

Reply all
Reply to author
Forward
0 new messages