Enjoy an ad free experience by logging in. Not a member yet?
Register .
10-30-2008, 05:26 PM
PM User |
#1
Regular Coder
Join Date: Nov 2007
Location: Leeds, UK
Posts: 514
Thanks: 24
Thanked 19 Times in 19 Posts
Microsoft why not XMLHttpRequest();
PHP Code:
< 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
10-31-2008, 05:13 PM
PM User |
#2
Regular Coder
Join Date: Nov 2007
Location: Leeds, UK
Posts: 514
Thanks: 24
Thanked 19 Times in 19 Posts
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
10-31-2008, 05:30 PM
PM User |
#3
Supreme Master coder!
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,292
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
The code isn't the same. This is the one your posted
Code:
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.
Code:
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.
__________________
|||| If you are getting paid to do a job, don't ask for help on it! ||||
10-31-2008, 10:44 PM
PM User |
#4
Senior Coder
Join Date: Jun 2007
Location: Urbana
Posts: 3,553
Thanks: 9
Thanked 480 Times in 463 Posts
i use.
Code:
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.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:15.2% IE7:0.5% IE8:8.4% IE9:8.5%
IE10:8.5%
11-03-2008, 09:33 AM
PM User |
#5
Regular Coder
Join Date: Nov 2007
Location: Leeds, UK
Posts: 514
Thanks: 24
Thanked 19 Times in 19 Posts
Quote:
Originally Posted by
rnd me
i use.
Code:
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
PHP Code:
function count1 ( $obj ){ if( $obj [ 0 ] != null ){ return $obj . length ; }else{ return false ; } }
i can not see why this dose not work
Last edited by barkermn01; 11-03-2008 at 09:36 AM ..
11-04-2008, 01:44 AM
PM User |
#6
Senior Coder
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
Quote:
Originally Posted by
rnd me
i use.
Code:
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
__________________
Tech Author [Ajax In Action, JavaScript : Visual Blueprint]
11-04-2008, 06:43 AM
PM User |
#7
Regular Coder
Join Date: Jul 2006
Posts: 399
Thanks: 33
Thanked 7 Times in 7 Posts
the same can be done with if else statements
11-04-2008, 11:41 AM
PM User |
#8
Senior Coder
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
Quote:
Originally Posted by
sybil6
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
__________________
Tech Author [Ajax In Action, JavaScript : Visual Blueprint]
11-04-2008, 01:25 PM
PM User |
#9
Regular Coder
Join Date: Jul 2006
Posts: 399
Thanks: 33
Thanked 7 Times in 7 Posts
even including both active X versions?
11-04-2008, 02:22 PM
PM User |
#10
Senior Coder
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
Try it and see what happens.
Eric
__________________
Tech Author [Ajax In Action, JavaScript : Visual Blueprint]
11-07-2008, 04:09 PM
PM User |
#11
Regular Coder
Join Date: Nov 2007
Location: Leeds, UK
Posts: 514
Thanks: 24
Thanked 19 Times in 19 Posts
Can we get back to the topic i think the AJAX is not working because the count function want wor
11-07-2008, 05:27 PM
PM User |
#12
Senior Coder
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
problem with your code is IE does not like innerhTML for adding select element. You need to use
Code:
var sel = document.getElementById("selectId");
sel.options[sel.options.length] = new Option("text","value");
to remove the options
Code:
sel.options.length = 0;
Eric
__________________
Tech Author [Ajax In Action, JavaScript : Visual Blueprint]
11-10-2008, 09:51 AM
PM User |
#13
Regular Coder
Join Date: Nov 2007
Location: Leeds, UK
Posts: 514
Thanks: 24
Thanked 19 Times in 19 Posts
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.
PHP 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
Last edited by barkermn01; 11-10-2008 at 12:18 PM ..
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 04:27 AM .
Advertisement
Log in to turn off these ads.