www.webdeveloper.com
Results 1 to 3 of 3

Thread: AJAX doesn't work in internet explorer!!!

  1. #1
    Join Date
    Aug 2006
    Posts
    87

    AJAX doesn't work in internet explorer!!!

    This is driving me nuts, as usual I was doing all my work in firefox, and it works PERFECTLY in firefox, then I go to test it out in IE and as per bl**dy usual, it doesn't work!!

    Does anyone know why?

    Here are the following files...

    search.php
    PHP Code:
    form name='myForm'>
    <
    select id="type" class="searchselect" style="display:block;"  onclick="ajaxFunction();" name="type">
    <
    option selected="selected">Please Select...</option>
    <
    option value="alternators">Alternator</option>
    <
    option value="startermotors">Starter Motor</option>
    </
    select>
    <
    select name="make" class="searchselect" id="make" onclick="ajaxFunction2();">
    </
    select>
    <
    select name="model" class="searchselect" id="model" onclick="ajaxFunction3();">
    </
    select>
    <
    select name="motor" class="searchselect" id="motor" onclick="ajaxFunction4();">
    </
    select>
    <
    select name="year" class="searchselect" id="year" onclick="ajaxFunction5();">
    </
    select>
    <
    input type="submit" style="display:none;" name="search" id="search"value="search &raquo;" />
    </
    form><br>
    <
    br>

    <
    div id="product" style="display:none; width:400px; padding:10px; color:#333333; border:3px dotted #cccccc;; font-family:Tahoma, Verdana, Arial; font-size:12px; background-color:#F2F2F2;">
    </
    div

    selects.js
    Code:
    <!-- 
    //Browser Support Code
    function ajaxFunction(){
    	var ajaxRequest;  // The variable that makes Ajax possible!
    	
    	try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Your browser broke!");
    				return false;
    			}
    		}
    	}
    	// Create a function that will receive data sent from the server
    	ajaxRequest.onreadystatechange = function(){
    		
    		
    		
    		if(ajaxRequest.readyState == 4){
    			document.myForm.make.innerHTML= ajaxRequest.responseText;
    		}
    	}
    
    	
    	var type = document.getElementById('type').value;
    	var make = document.getElementById('make').value;
    	/*var make = document.getElementById('make').value;
    	var model = document.getElementById('model').value;
    	var motor = document.getElementById('motor').value;
    	var year = document.getElementById('year').value;
    	
    	var queryString = "?type=" + type + "&make=" + make + "&model=" + model + "&motor=" + motor + "&year=" + year;*/
    	
    	var queryString = "?type=" + type;
    	
    	ajaxRequest.open("GET", "/customers/ajax/ajax.php" + queryString, true);
    	ajaxRequest.send(null); 
    }
    
    
    
    
    
    function ajaxFunction2(){
    	var ajaxRequest;  // The variable that makes Ajax possible!
    	
    	try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Your browser broke!");
    				return false;
    			}
    		}
    	}
    	// Create a function that will receive data sent from the server
    	ajaxRequest.onreadystatechange = function(){
    		
    		
    		
    		if(ajaxRequest.readyState == 4){
    			document.myForm.model.innerHTML= ajaxRequest.responseText;
    		}
    	}
    
    	
    	var type = document.getElementById('type').value;
    	var make = document.getElementById('make').value;
    	/*var make = document.getElementById('make').value;
    	var model = document.getElementById('model').value;
    	var motor = document.getElementById('motor').value;
    	var year = document.getElementById('year').value;
    	
    	var queryString = "?type=" + type + "&make=" + make + "&model=" + model + "&motor=" + motor + "&year=" + year;*/
    	
    	var queryString = "?type=" + type + "&make=" + make;
    	
    	ajaxRequest.open("GET", "/customers/ajax/ajax.php" + queryString, true);
    	ajaxRequest.send(null); 
    }
    
    
    
    
    
    function ajaxFunction3(){
    	var ajaxRequest;  // The variable that makes Ajax possible!
    	
    	try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Your browser broke!");
    				return false;
    			}
    		}
    	}
    	// Create a function that will receive data sent from the server
    	ajaxRequest.onreadystatechange = function(){
    		
    		
    		
    		if(ajaxRequest.readyState == 4){
    			document.myForm.motor.innerHTML= ajaxRequest.responseText;
    		}
    	}
    
    	
    	var type = document.getElementById('type').value;
    	var make = document.getElementById('make').value;
    	var model = document.getElementById('model').value;
    	/*var year = document.getElementById('year').value;
    	
    	var queryString = "?type=" + type + "&make=" + make + "&model=" + model + "&motor=" + motor + "&year=" + year;*/
    	
    	var queryString = "?type=" + type + "&make=" + make + "&model=" + model;
    	
    	ajaxRequest.open("GET", "/customers/ajax/ajax.php" + queryString, true);
    	ajaxRequest.send(null); 
    }
    
    
    function ajaxFunction4(){
    	var ajaxRequest;  // The variable that makes Ajax possible!
    	
    	try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Your browser broke!");
    				return false;
    			}
    		}
    	}
    	// Create a function that will receive data sent from the server
    	ajaxRequest.onreadystatechange = function(){
    		
    		
    		
    		if(ajaxRequest.readyState == 4){
    			document.myForm.year.innerHTML= ajaxRequest.responseText;
    		}
    	}
    
    	
    	var type = document.getElementById('type').value;
    	var make = document.getElementById('make').value;
    	var model = document.getElementById('model').value;
    	var motor = document.getElementById('motor').value;
    	/*var year = document.getElementById('year').value;
    	
    	var queryString = "?type=" + type + "&make=" + make + "&model=" + model + "&motor=" + motor + "&year=" + year;*/
    	
    	var queryString = "?type=" + type + "&make=" + make + "&model=" + model + "&motor=" + motor;
    	
    	ajaxRequest.open("GET", "/customers/ajax/ajax.php" + queryString, true);
    	ajaxRequest.send(null); 
    }
    
    
    
    
    
    
    
    
    
    
    function ajaxFunction5(){
    	var ajaxRequest;  // The variable that makes Ajax possible!
    	
    	try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Your browser broke!");
    				return false;
    			}
    		}
    	}
    	// Create a function that will receive data sent from the server
    	ajaxRequest.onreadystatechange = function(){
    		
    		
    		
    		if(ajaxRequest.readyState == 4){
    			var ajaxDisplay = document.getElementById('product');
    			ajaxDisplay.innerHTML = ajaxRequest.responseText;
    		}
    	}
    
    	
    	var type = document.getElementById('type').value;
    	var make = document.getElementById('make').value;
    	var model = document.getElementById('model').value;
    	var motor = document.getElementById('motor').value;
    	var year = document.getElementById('year').value;
    	
    	var queryString = "?type=" + type + "&make=" + make + "&model=" + model + "&motor=" + motor + "&year=" + year;
    	
    	ajaxRequest.open("GET", "/customers/ajax/ajax.php" + queryString, true);
    	ajaxRequest.send(null); 
    }
    
    //-->

    ajax.php
    PHP Code:
    <?
    $type 
    $_GET['type'];

    if(
    $type=='alternators'){ $field="observations"; } else{ $field="motor"; }



    $make $_GET['make'];
    $model $_GET['model'];
    $motor $_GET['motor'];
    $motor trim($motor);

    $year $_GET['year'];


    if(!empty(
    $type) && empty($make) && empty($model) && empty($motor)){

        
    $query "SELECT DISTINCT make FROM $type ORDER BY make ASC";
        
    $result mysql_query($query);
        while(
    $fetch=mysql_fetch_object($result)){
            echo
    "<option value=\"$fetch->make\">$fetch->make</option>";
        }
        
    }

    if(!empty(
    $make) && empty($model)){

        
    $query "SELECT * FROM $type WHERE make='$make' ORDER BY model ASC";
        
    $result mysql_query($query);
        while(
    $fetch=mysql_fetch_object($result)){
            echo
    "<option value=\"$fetch->model\">$fetch->model</option>";
        }
    }

    if(!empty(
    $make) && !empty($model) && empty($motor)){

        
    $query "SELECT * FROM $type WHERE make='$make' AND model='$model' ORDER BY model ASC";
        
    $result mysql_query($query);
        while(
    $fetch=mysql_fetch_object($result)){
        
    $fetchmotor $fetch->$field;
        
    $fetchmotor2 str_replace("+""@@plus@@"$fetchmotor);
            echo
    "<option value=\"$fetchmotor2\">$fetchmotor</option>";
        }
    }

    if(!empty(
    $make) && !empty($model) && !empty($motor) && empty($year)){

        
    $motor str_replace("@@plus@@""+"$motor);
        
    $query "SELECT * FROM $type WHERE make='$make' AND model='$model' AND $field='$motor' ORDER BY year ASC";
        
    $result mysql_query($query);
        
    $count mysql_num_rows($result);
    //        echo"query: $query";
        
    while($fetch=mysql_fetch_object($result)){
            echo
    "<option value=\"$fetch->year\">$fetch->year</option>";
        }
    }


    if(!empty(
    $make) && !empty($model) && !empty($motor) && !empty($year)){

        
    $motor str_replace("@@plus@@""+"$motor);
        
    $query "SELECT * FROM $type WHERE make='$make' AND model='$model' AND $field='$motor' AND year='$year'";
        
    $result mysql_query($query);
        
    $count mysql_num_rows($result);
        while(
    $fetch=mysql_fetch_object($result)){
            echo
    "Product: $fetch->make$fetch->model, partno: $fetch->part_no";
        }
    }






    ?>

  2. #2
    Join Date
    Aug 2006
    Posts
    87
    if you want to test it out, go here... (works in firefox, not IE)

    user following login details:

    test
    test123

    Please can someone help, i bet its something really really small!

    MANY MANY THANKS IN ADVANCE.

  3. #3
    Join Date
    May 2005
    Location
    Dirty Jersey
    Posts
    1,400
    since there is no "want to test it out" page, heres some questions and suggestions:

    first, does IE give you any error in the bottom left corner?

    second, place alerts after ending curly braces. have them alert information you know should be available at the end of the specific conditional. for instance:

    Code:
    try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Your browser broke!");
    				return false;
    			}
    		}
    	}
    alert(ajaxRequest)
    this alert obviously should contain some object. perhaps, stick an alert into "onreadystatechange" to see if thats being called properly. stick an alert under the open method just to see if it fires, and stick an alert under the send. this will let you know where IE is choking, if that is indeed the fact.
    Last edited by Angry Black Man; 03-02-2008 at 01:08 PM.

    1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
    2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
    3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles