The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

XMLHttpRequest and Multiple Browser Windows

Within an AJAX application, does opening a new browser window create another instance of the XMLHttpRequest object, or are they shared?
John Topley Send private email
Wednesday, June 01, 2005
 
 
I'll be scared if it's only 1 object.

But seriously, this is a good question.
Michael Sica Send private email
Wednesday, June 01, 2005
 
 
Isn't XMLHttpRequest is class (or the closestest thing you can get in Javascript) that you create instances of?
Almost H. Anonymous Send private email
Wednesday, June 01, 2005
 
 
Yes. The question is what happens if you've instantiated an XMLHttpRequest and then the user opens a new browser window, thus creating two views of the same application. Is there then one XMLHttpRequest instance or two?
John Topley Send private email
Wednesday, June 01, 2005
 
 
"Is there then one XMLHttpRequest instance or two?"

Two.  When the user opens a new window your page is reexecuted and any Javascript is rerun.  Thus a completely new instance will be created.
Almost H. Anonymous Send private email
Wednesday, June 01, 2005
 
 
This is more than one.

A simple way to see this is open GMail in two different browser windows/tabs and sit and watch as you get new mail.

Unless you load both at the same instant, they will update on different intervals and you'll see your message count grow out of sync.


What you're thinking of is a Singleton Pattern and in this scenario could potentially lead to one XMLHttpRequest hijacking another... the problems of this could be bad.
KC Send private email
Wednesday, June 01, 2005
 
 
It's a COM object; same as all other COM objects that are instantiated from Javascript. And there is no such thing as AJAX, just some scripting and COM that's been around for years.
Tom H
Wednesday, June 01, 2005
 
 
Basically everything in a new window is a clone of the old one. URL. Navigation stack. Etc.
mb Send private email
Thursday, June 02, 2005
 
 
Though if you use window.open and have control over both windows, you could share an object.

o = window.open(...)
o.foo = window.foo;

now both window.foo objects are the same.
mb Send private email
Thursday, June 02, 2005
 
 
Thanks everyone.

"It's a COM object; same as all other COM objects that are instantiated from Javascript. And there is no such thing as AJAX, just some scripting and COM that's been around for years."

If there's no such thing as AJAX, then how did you know what I was talking about? ;-) Of course it's not a COM object if you're using Mozilla or Safari.
John Topley Send private email
Thursday, June 02, 2005
 
 
"Within an AJAX application..."

Okay, define "AJAX application", and try to convince me that it's somehow a different "application" than other DHTML with javascript and client side components.
Anony Coward
Thursday, June 02, 2005
 
 
Isn't the debate over whether the name AJAX means anything or not getting a little boring now? If it offends you then I request that you perform a mental search and replace of "AJAX" with "Remote Scripting" or whatever your preferred description is whenever you come across it.

I happen to think that the term AJAX does add value* for the reasons discussed by Simon Willison here: http://simon.incutio.com/archive/2005/04/19/useful

* However, I think the XML part is optional!
John Topley Send private email
Thursday, June 02, 2005
 
 
Two things about "AJAX" irritate me. First, from your original post:

"Within an AJAX application, does opening a new browser window create another instance of the XMLHttpRequest object..."

Hello? Do you really think it would be different "within and AJAX application" versus outside of an AJAX application? Saying it's "inside an AJAX application" means nothing.

Second, using XMLHttpRequest is IMHO an unnecessarily cumbersome way to do the server side scripting. XML-RPC was designed years ago to make remote procedure calls easy, no need to fuss with XML.
Anony Coward
Friday, June 03, 2005
 
 
"XML-RPC was designed years ago to make remote procedure calls easy, no need to fuss with XML."

XMLHttpRequest is a the method for which you can make XML-RPC calls (or any other HTTP-transported call) from Javascript.  Perhaps you misunderstand it.

As for AJAX, it's really no different from "REST".  It's an acronym for describing already existing processes.
Almost H. Anonymous Send private email
Friday, June 03, 2005
 
 
You don't even have to use XML with XMLHttpRequest.
John Topley Send private email
Friday, June 03, 2005
 
 
"XMLHttpRequest is a the method for which you can make XML-RPC calls (or any other HTTP-transported call) from Javascript.  Perhaps you misunderstand it."

I don't misunderstand it, in fact I use XML-RPC frequently and I know the client and/or server can use XMLHttpRequest under the covers (but doesn't have to). But I don't care if it does or not, my code just makes procedure calls that are executed on the server.
Anony Coward
Friday, June 03, 2005
 
 
"You don't even have to use XML with XMLHttpRequest"

True, it's just a mechanism for passing strings. But you should take a look at using XMLRPC instead of passing strings around, it really is easier because all the marshalling/unmarshalling is done for you:

http://www.xmlrpc.com/
Tom H
Friday, June 03, 2005
 
 
Pah. XML-RPC isn't even correct XML.
Matthew Wilson
Sunday, June 12, 2005
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz