This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

XMLHttpRequest

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the role of XMLHttpRequest? Where I get this object? Some framework?
 
Author
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XMLHttpRequest to a large degree is what makes Ajax, Ajax.

The object is part of the browser, but how you instantiate it depends on the browser. Here is the code I like to use.

function FactoryXMLHttpRequest() {
if( window.XMLHttpRequest) {
return new XMLHttpRequest();
}
else if( window.ActiveXObject) {
var msxmls = new Array(
'Msxml2.XMLHTTP.5.0',
'Msxml2.XMLHTTP.4.0',
'Msxml2.XMLHTTP.3.0',
'Msxml2.XMLHTTP',
'Microsoft.XMLHTTP');
for (var i = 0; i < msxmls.length; i++) {
try {
return new ActiveXObject(msxmls[i]);
} catch (e) {
}
}
}
throw new Error( "Could not instantiate factory" ;
}
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In this case, what are we supposed to do ? Tell the customer to change his web browser ?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tell them to use a real browser like firefox or develop a solution that does not rely on the XMLHttpRequest object.

There is a discussion on that here: https://coderanch.com/t/117452/HTML-JavaScript/AJAX

I use an iframe set up that I been working on to get around this problem. Still have not put it into production, but it should be there soon.

The buggest flaw is disabling ActiveX on IE. Kills Ajax and I have seen that.

Eric
[ February 22, 2006: Message edited by: Eric Pascarello ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, Christian's Permutation Pattern.

The buggest flaw is disabling ActiveX on IE. Kills Ajax and I have seen that.


Yes, that what scares me from using Ajax in business, as we do not know what browser the user are using, and what settings they have. It's difficult to say forget about your stinky browser and use a decent one
Well, it's probably a matter of time. Browsers will hopefully offer better ingretation for Ajax, if developpers keep on using it.
 
Christian Gross
Author
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank-you Satou... I was hoping somebody would bite on that one... The throw is on purpose and very important.

One of the big problems that we have is that we write JavaScript code to deal with cases where a browser might or might not support a specific feature. This has lead to JavaScript code that IMO ressembles spaghetti. In fact the resulting code is a major headache!

What we seem to have forgotten is that a device that supports one feature and not another is not a simple decision in a JavaScript code. A browser that supports Ajax has a completely different user experience than a browser that does not support Ajax. This argument can be extended to supporting text based only devices, or smaller devices. So in other words with our simple JavaScript we are trying to serve content to all devices except that it does not work! The JavaScript that supposedly can decide, decides on a small subset of devices! I have tested many websites and a scarily large number are only suited to work in very limited situations. Why do they do this? Laziness! Companies like Yahoo and Google do the right thing at the right time (I was surprised by this). Whereas AOL, and Microsoft don't.

So let's tie this back to the little exception. Knowing that writing JavaScript with a couple of decisions is not going to solve our cross-device problem what's the solution? Answer: REST and the Permutations pattern that says you have a resource and representation. Whenever a device accesses a resource the server will decide which representation is sent to the client. Therefore, if the representation contains a reference to Ajax, then the server has determined that the client is capable of running Ajax. And if the XMLHttpRequest object cannot be instantiated it is an error! You do not want a quiet error, you want fireworks and explicit knowledge that something went wrong. In the case of the factory that was the inability to create the XMLHttpRequest object. Clients that do not support Ajax are sent different representations, and hence will not contain the code to instantiate the XMLHttpRequest.

Some of you have already mentioned, "Ah man that's a lot of work". No, in fact it is less work. Because the "easier" implementation is an implementation that does not function properly. It's like saying, "Ahh man that's a lot of work and I want to release this software that works (probably)". Remember that these days the computer is popular, but cell phone surfing is coming in vogue!

So I ask you, are you ready with your applications to be viewed by a cell phone?
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic