CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2004
    Location
    .hell On Earth.
    Posts
    91

    Angry XMLHTTP does not work on IE

    hello

    the following code works well on FireFox Opera Safari and Netscape navigator but not on IE v6.0

    Code:
    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    try
     {
     xmlHttp=new XMLHttpRequest();
     }
    catch (e)
     {
     try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
    return xmlHttp;
    
    }
    anybody knows why!

  2. #2
    Join Date
    Jul 2007
    Location
    Sweden
    Posts
    331

    Re: XMLHTTP does not work on IE

    If you're running the script locally, IE might block it due to default security settings. It could also be blocked anywhere if the security settings have been changed.

    It would help us to know what return value you're getting, if it reaches that point. If it doesn't reach the return call, that means there is a script error in which case we need to know what that is. "does not work" isn't much to go on.

    Once you've got it working, here's an additional method you can add to the try list, if you want to support some less common browsers: window.createRequest().
    Last edited by andreasblixt; August 11th, 2007 at 11:27 AM.

  3. #3
    Join Date
    May 2002
    Posts
    10,943

    Re: XMLHTTP does not work on IE

    You could put alert() functions in each of the catch statements. That would alert you if they are functioning.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  4. #4
    Join Date
    Sep 2004
    Location
    .hell On Earth.
    Posts
    91

    Re: XMLHTTP does not work on IE

    window.createRequest(); gonna start studying that one


    i insert alert(); functions and it reaches to

    Code:
    function GetXmlHttpObject()
    {
    
    var xmlHttp=null;
    try
     {
     xmlHttp=new XMLHttpRequest();
     }
    catch (e)
     {
    
     try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    alert('HERE'); //IT REACHES HERE
      }
     catch (e)
      {
    
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
    return xmlHttp;
    }
    i tried Msxml2.XMLHTTP.6.0 but still no result ..

  5. #5
    Join Date
    Sep 2004
    Location
    .hell On Earth.
    Posts
    91

    Re: XMLHTTP does not work on IE

    window.createRequest does not work either.. tried the following code

    Code:
    var xmlhttp
    
    function GetXmlHttpObject()
    {
    var xmlhttp=false;
    
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    	try {
    		xmlhttp = new XMLHttpRequest();
    	} catch (e) {
    		xmlhttp=false;
    	}
    }
    if (!xmlhttp && window.createRequest) {
    	try {
    		xmlhttp = window.createRequest();
    	} catch (e) {
    		xmlhttp=false;
    	}
    }
    return xmlhttp;
    }
    it works on FF Opera Safari but not IE.. now i tried

    http://www.w3schools.com/php/php_ajax_database.asp on my IE and it works (the example) there works..

  6. #6
    Join Date
    Jul 2007
    Location
    Sweden
    Posts
    331

    Re: XMLHTTP does not work on IE

    If you get the "HERE" alert box, that means it successfully created the XML http request (an exception would have skipped the alert statement.) Most likely your error stems from another part of your code, most likely due to something not working in IE specifically.

    You still haven't told us anything except "it doesn't work." We can't give you any more help unless you tell us what error you're getting (or what behavior you're seeing) or show us more code.

  7. #7
    Join Date
    Sep 2004
    Location
    .hell On Earth.
    Posts
    91

    Re: XMLHTTP does not work on IE

    after testing i found out that the problem is as you said andrea is not in the xmlHttp request.

    Code:
    <?php
    $q=$_GET["q"];
    $con = mysql_connect('s', 'u', 'p');
    if (!$con)
     {
     die($ERROR_CONNECTING_MYSQL . mysql_error());
     }
    
    mysql_select_db("world", $con);
    
    $sql="SELECT DISTINCT City FROM geoinfo WHERE country = '".$q."'";
    
    $result = mysql_query($sql);
    
    echo "<option>Select a City</option>";
    while($row = mysql_fetch_array($result))
     {
    echo "<option value =\"" . $row['City'] . "\">" . $row['City'] . "</option>";
    
     }
    echo "<option value = Other...>(City not listed - Click here)</option>";
    
    mysql_close($con);
    
    ?>
    the above response is suppose to go to

    Code:
    document.getElementById('P_City').innerHTML=xmlHttp.responseText
    where P_City is an id of a <select> tag. it works in all browsers but not in IE.

    The only way to make it work in IE is by changing the PHP code to

    Code:
    <?php
    $q=$_GET["q"];
    $con = mysql_connect('s', 'u', 'p');
    if (!$con)
     {
     die($ERROR_CONNECTING_MYSQL . mysql_error());
     }
    
    mysql_select_db("world", $con);
    
    $sql="SELECT DISTINCT City FROM geoinfo WHERE country = '".$q."'";
    
    $result = mysql_query($sql);
    echo "<select>";//CHANGE
    echo "<option>Select a City</option>";
    while($row = mysql_fetch_array($result))
     {
    echo "<option value =\"" . $row['City'] . "\">" . $row['City'] . "</option>";
    
     }
    echo "<option value = Other...>(City not listed - Click here)</option>";
    echo "</select>";//CHANGE
    mysql_close($con);
    
    ?>
    and creating a new <div> tag to load the above response text in

    Code:
    document.getElementById('NEWP_City').innerHTML=xmlHttp.responseText
    which means that i must first remove the <select> tag from the html page and load the whole tag dynamically. but can not load the <options> only .

    Is this an error in IE or do i need to update my IE..??

    hope this is clear enough.
    kimoo

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured