Tell Gus what you think, but remember- you are in his home. Be a good guest.
IIRC Google Maps is using a hidden IFRAME for precisely the last of your reasons---IFRAMEs show up in your history.
Posted by Byron Ellis at February 24th 2005 07:36 PM
Cool- thanks for the tip Byron.
Posted by August Mueller at February 24th 2005 07:41 PM
Gus, you might want to add a var declaration to your req variable. Without the "var" bit, the variable is actually a global. This might not matter much, but it is significant.
So you'd have:
var req=getXMLHttpRequest();
instead of
req=getXMLHttpRequest();
Posted by Jeff Watkins at February 25th 2005 05:09 AM
You are half way there Gus :)
You can do this even better. For a few projects I have worked on, I have done something similar to what you have done, except I use closures instead of anonymous functions, and I pass function pointers around too. This makes it a lot cleaner and less crufty with all that status checking that goes on.
You basically have something like this:
function sendRequest(url, callback, errback) {
var req = getXMLHttpRequest();
req.open("GET", url, true);
function dispatch() {
if (req.readyState == 4) {
if (req.status == 200) {
callback();
} else {
errback();
}
}
}
req.onReadyStateChange = dispatch;
}
This way you can pass in custom callbacks, and share the same request/response code. This is just a very simple example. You can (and I have) define RESTian protocols and messaging systems through this kind of methodology.
Anyway, good post.
Posted by Jonathan LaCour at February 25th 2005 06:51 AM