-
August 11th, 2007, 10:41 AM
#1
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!
-
August 11th, 2007, 11:23 AM
#2
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.
-
August 11th, 2007, 05:57 PM
#3
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.
-
August 12th, 2007, 09:02 AM
#4
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 ..
-
August 12th, 2007, 09:18 AM
#5
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..
-
August 12th, 2007, 01:15 PM
#6
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.
-
August 14th, 2007, 06:54 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|