Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #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

  • #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

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 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!||||

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,378
    Thanks
    11
    Thanked 592 Times in 572 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 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #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 View Post
    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.

  • #6
    Senior Coder A1ien51's Avatar
    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 View Post
    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]

  • #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

  • #8
    Senior Coder A1ien51's Avatar
    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 View Post
    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]

  • #9
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    even including both active X versions?

  • #10
    Senior Coder A1ien51's Avatar
    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
    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

  • #12
    Senior Coder A1ien51's Avatar
    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]

  • #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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •