...

View Full Version : Microsoft why not XMLHttpRequest();



barkermn01
10-30-2008, 05:26 PM
<script type="text/javascript" language="javascript">
function GetXmlHttpObject(){
var xmlHttp;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{ // Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}
</script>
<script type="text/javascript" language="javascript">
function getNext(){
// Set Ajax
xmlHttp = GetXmlHttpObject();

// Set Whats been Sepected
$product = document.getElementById("product").value;
$type = document.getElementById("type").value;
$colour = document.getElementById("colour").value;
$size = document.getElementById("size").value;
$depth = document.getElementById("depth").value;

if($product == ''){
$address = 'defines.php';
xmlHttp.open("GET",$address,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState == 4){
$response = xmlHttp.responseText.split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
}
document.getElementById("product").innerHTML = $innerHTML;
}
}
}

if($product != '' && $type == ''){
$address = 'defines.php?PRODUCT='+$product;
xmlHttp.open("GET",$address,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState == 4){
$response = xmlHttp.responseText.split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
}
document.getElementById("type").innerHTML = $innerHTML;
}
}
}
if($type != '' && $colour == ''){
$address = 'defines.php?PRODUCT='+$product+'&TYPE='+$type;
xmlHttp.open("GET",$address,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState == 4){
$response = xmlHttp.responseText.split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
}
document.getElementById("colour").innerHTML = $innerHTML;
}
}
}
if($colour != '' && $size == ''){
$address = 'defines.php?PRODUCT='+$product+'&TYPE='+$type+'&COLOUR='+$colour;
xmlHttp.open("GET",$address,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState == 4){
$response = xmlHttp.responseText.split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
}
document.getElementById("size").innerHTML = $innerHTML;
}
}
}
if($size != '' && $depth == ''){
$address = 'defines.php?PRODUCT='+$product+'&TYPE='+$type+'&COLOUR='+$colour+'&SIZE='+$size;
xmlHttp.open("GET",$address,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState == 4){
$response = xmlHttp.responseText.split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
}
document.getElementById("depth").innerHTML = $innerHTML ;
}
}
}
if($size != '' && $depth != ''){
$address = 'defines.php?PRODUCT='+$product+'&TYPE='+$type+'&COLOUR='+$colour+'&SIZE='+$size+'&DEPTH='+$depth;
xmlHttp.open("GET",$address,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState == 4){
$response = xmlHttp.responseText;
$innerHTML = $response;
document.getElementById("cost").innerHTML = $innerHTML;
}
}
}
}
</script>


Ok Help this wont work in IE works in every other browser but IE so can some one please help me i cannot see a coding error in this it has to be in the function GetXmlHttpObject();
Any help please

barkermn01
10-31-2008, 05:13 PM
Ok any one,

I have one site that uses the Same code and works fine in IE
check it http://www.riverside-york.co.uk - click on booking
why dose this one not
http://mangos-site.co.uk/barkston/show.html

Try it in Any other browser but IE it works Try it in IE it dosent but riverside works on IE even though it is same code

_Aerospace_Eng_
10-31-2008, 05:30 PM
The code isn't the same. This is the one your posted


function GetXmlHttpObject(){
var xmlHttp;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{ // Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}

This is the one from the riverside site.

function GetXmlHttpObject(){
var xmlHttp=null;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e){
//Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

The first one has 3 try catch blocks where as the last one only has two. xmlHttp is also set to null.

rnd me
10-31-2008, 10:44 PM
i use.


function GetXmlHttpObject(){
return !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
}


i don't like try because it hides errors. it can slightly slow execution as well, not that it matters much in this case.

barkermn01
11-03-2008, 09:33 AM
i use.


function GetXmlHttpObject(){
return !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
}


i don't like try because it hides errors. it can slightly slow execution as well, not that it matters much in this case.

Ok will try that but that dose not support ActiveXObject('Msxml2.XMLHTTP')

Any one with idears to why a count function works in's in all but IE?
http://mangos-site.co.uk/barkston/show.html



function count1($obj){
if($obj[0] != null){
return $obj.length;
}else{
return false;
}
}


i can not see why this dose not work

A1ien51
11-04-2008, 01:44 AM
i use.


function GetXmlHttpObject(){
return !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
}


i don't like try because it hides errors. it can slightly slow execution as well, not that it matters much in this case.

Actually try catch is sort of needed here. If you disable activeX on a computer, it will throw an error.

Eric

sybil6
11-04-2008, 06:43 AM
the same can be done with if else statements

A1ien51
11-04-2008, 11:41 AM
the same can be done with if else statements

If that was directed to me with the try catche, the else statements still throws an error. Strange yes, but it is IE we are talking about. :)

Eric

sybil6
11-04-2008, 01:25 PM
even including both active X versions?

A1ien51
11-04-2008, 02:22 PM
Try it and see what happens.

Eric

barkermn01
11-07-2008, 04:09 PM
Can we get back to the topic i think the AJAX is not working because the count function want wor

A1ien51
11-07-2008, 05:27 PM
problem with your code is IE does not like innerhTML for adding select element. You need to use



var sel = document.getElementById("selectId");
sel.options[sel.options.length] = new Option("text","value");


to remove the options



sel.options.length = 0;


Eric

barkermn01
11-10-2008, 09:51 AM
Thank's i will try that
*EDIT*
Sorry bad news, it dose not work,
But now it is my anti AJAX work arround, using Iframes so if AJAX Fails Iframe Works IE is using the Iframe work arround not sure why the AJAX don't work

So here is my code.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function GetXmlHttpObject(){
var xmlHttp=null;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e){
//Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

function count1($obj){
if($obj[0] != null){
return $obj.length;
}else{
return false;
}
}
//-->
</script>
<script type="text/javascript">
<!--
function getNext(){
// Set Ajax
xmlHttp=GetXmlHttpObject();

// Set Whats been Sepected
$product = document.getElementById("product").value;
$type = document.getElementById("type").value;
$colour = document.getElementById("colour").value;
$size = document.getElementById("size").value;
$depth = document.getElementById("depth").value;

if($product == ''){
$address = 'defines.php';
xmlHttp.open("GET",$address,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState == 4){
$response = xmlHttp.responseText.split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count1($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
var sel = document.getElementById("product");
sel.options[sel.options.length] = new Option($response[$i],$response[$i]);
}
//document.getElementById("product").innerHTML = $innerHTML;
}
}
if(xmlHttp.responseText == undefined || xmlHttp == null){
$response = iframeGet().split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count1($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
var sel = document.getElementById("product");
sel.options[sel.options.length] = new Option($response[$i],$response[$i]);
}
//document.getElementById("product").innerHTML = $innerHTML;
}

}
if($product != '' && $type == ''){
$address = 'defines.php?PRODUCT='+$product;
xmlHttp.open("GET",$address,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState == 4){
$response = xmlHttp.responseText.split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count1($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
var sel = document.getElementById("type");
sel.options[sel.options.length] = new Option($response[$i],$response[$i]);
}
//document.getElementById("type").innerHTML = $innerHTML;
}
}
if(xmlHttp.responseText == undefined || xmlHttp == null){
$response = iframeGet().split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count1($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
var sel = document.getElementById("type");
sel.options[sel.options.length] = new Option($response[$i],$response[$i]);
}
//document.getElementById("type").innerHTML = $innerHTML;
}
}
if($type != '' && $colour == ''){
$address = 'defines.php?PRODUCT='+$product+'&TYPE='+$type;
xmlHttp.open("GET",$address,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState == 4){
$response = xmlHttp.responseText.split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count1($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
var sel = document.getElementById("colour");
sel.options[sel.options.length] = new Option($response[$i],$response[$i]);
}
//document.getElementById("colour").innerHTML = $innerHTML;
}
}
if(xmlHttp.responseText == undefined || xmlHttp == null){
$response = iframeGet().split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count1($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
var sel = document.getElementById("colour");
sel.options[sel.options.length] = new Option($response[$i],$response[$i]);
}
//document.getElementById("colour").innerHTML = $innerHTML;
}
}
if($colour != '' && $size == ''){
$address = 'defines.php?PRODUCT='+$product+'&TYPE='+$type+'&COLOUR='+$colour;
xmlHttp.open("GET",$address,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState == 4){
$response = xmlHttp.responseText.split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count1($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
var sel = document.getElementById("size");
sel.options[sel.options.length] = new Option($response[$i],$response[$i]);
}
//document.getElementById("size").innerHTML = $innerHTML;
}
}
if(xmlHttp.responseText == undefined || xmlHttp == null){
$response = iframeGet().split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count1($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
var sel = document.getElementById("size");
sel.options[sel.options.length] = new Option($response[$i],$response[$i]);
}
//document.getElementById("size").innerHTML = $innerHTML;
}
}
if($size != '' && $depth == ''){
$address = 'defines.php?PRODUCT='+$product+'&TYPE='+$type+'&COLOUR='+$colour+'&SIZE='+$size;
xmlHttp.open("GET",$address,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState == 4){
$response = xmlHttp.responseText.split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count1($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
var sel = document.getElementById("depth");
sel.options[sel.options.length] = new Option($response[$i],$response[$i]);
}
//document.getElementById("depth").innerHTML = $innerHTML ;
}
}
if(xmlHttp.responseText == undefined || xmlHttp == null){
$response = iframeGet().split(/\s?\;\s{0,3}/g);
$innerHTML = '<option selected="selected" value=""></option>\n';
$max = count1($response) - 1;
$i = 0;
while($i!=$max){
$innerHTML = $innerHTML + '<option value="'+$response[$i]+'">'+$response[$i]+'</option>\n';
$i++;
var sel = document.getElementById("depth");
sel.options[sel.options.length] = new Option($response[$i],$response[$i]);
}
//document.getElementById("depth").innerHTML = $innerHTML ;
}
}
if($size != '' && $depth != ''){
$address = 'defines.php?PRODUCT='+$product+'&TYPE='+$type+'&COLOUR='+$colour+'&SIZE='+$size+'&DEPTH='+$depth;
xmlHttp.open("GET",$address,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState == 4){
$response = xmlHttp.responseText;
$innerHTML = $response;
document.getElementById("cost").innerHTML = $innerHTML;
}
}
if(xmlHttp.responseText == undefined || xmlHttp == null){
$innerHTML = iframeGet();
document.getElementById("cost").innerHTML = $innerHTML;
}
}
}

function iframeGet(){
var iframeContents = document.getElementById("dataStream").contentDocument.body.innerHTML;
return iframeContents;
}
//-->
</script>
</head>

<body onload="getNext();">
<iframe style="width:200px; height:25px;" src="defines.php" id="dataStream" width="200px" height="25px;"></iframe>
Barkston Cuting Calulator<br />
<br />
<span id="notifyLoading">Loading if not loaded <a href="javascript:;" onclick="getNext();">click here</a></span><br />
<table width="347" border="0">
<tr>
<td width="79"><div align="right">Product</div></td>
<td width="258">
<select name="product" onchange="getNext();" id="product">
<option value=""></option>
</select>
</td>
</tr>
<tr>
<td><div align="right">Type</div></td>
<td>
<select name="type" onchange="getNext();" id="type">
<option selected="selected" value=""></option>
</select>
</td>
</tr>
<tr>
<td><div align="right">Colour</div></td>
<td>
<select name="colour" onchange="getNext();" id="colour">
<option selected="selected" value=""></option>
</select>
</td>
</tr>
<tr>
<td><div align="right">Size</div></td>
<td>
<select name="size" onchange="getNext();" id="size">
<option selected="selected" value=""></option>
</select>
</td>
</tr>
<tr>
<td><div align="right">Depth</div></td>
<td>
<select name="depth" onchange="getNext();" id="depth">
<option selected="selected" value=""></option>
</select>
</td>
</tr>
</table>
<br />
COST:<span id="cost"></span><br />
</body>
</html>


Or live at http://www.mangos-site.co.uk/barkston/show.html,
I can See the IFrame at the moment just for testing purposis, but IE allways throws error,
"The data necessary to complete this operation is no yet available", even though the iframe as fully loaded as i can see the data in it

Please note the online one i am working on all the time



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum