IE Ajax Weirdness

D

DonO

Hopefully something here will jump out at someone. I can't find out
why this doesn't show any errors in FF, but in IE, it throws an error.

I have a page with the following code...

<html>
<head>

<title>whatever</title>

<script type="text/javascript">

function createRequestObject() {
if(navigator.appName == "Microsoft Internet Explorer"){
var ro = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
var ro = new XMLHttpRequest();
}
return ro;
}

var http = createRequestObject();

function handleResponse(inUpdateDiv) {
if (http.readyState == 4) {

var response = http.responseText;

if (http.status == 200) {
document.getElementById(inUpdateDiv).innerHTML = response;
}
else {
alert('There was a problem with the request.');
}
}
}



function build_employee_info() {
http.open('get', '/_ajax/AJAX_display_emp_profile_info.php');
http.onreadystatechange = function (){
handleResponse('ajax_employee_profile_info');
}
http.send(null);
}

// remove item from tblEmployeeInfo
function removeEmpData (inID) {
if(confirm_delete()){
var urlString = "";
if(inID != ''){
urlString += "&uid=" + inID;
http.open('get', '/_ajax/AJAX_update_profile.php?
action=rm'+urlString);
http.onreadystatechange = function (){
build_employee_info();
}
http.send(null);
}
}
}
</script>
</head>
<body onload="build_employee_info()">

{misc html}

<!-- this is where the ajax call drops in the results -->
<div id="ajax_employee_profile_info" style="clear:both;"></div>

</body>
</html>


The PHP page "AJAX_display_emp_profile_info.php" just does a DB call
and loads the current info for an employee's profile. There are links
to Add/Edit/Remove items in the content that pulls in. If you click a
link to do the "Remove", it will call the "removeEmpData()" function
above. This call is a second AJAX call to go in and remove the data
from the database. When it finishes, it should return to the
build_employee_info() which will refresh all the info in the <div
id="ajax_employee_profile_info"> tag.

It works fine in FF, but not IE 6. IE loads the info fine initially
but errors on any of the edits (though it does run the php ok, so if I
say "No" to show debugging, it eventually gets to the end result.)

Saying "yes" to show debugging takes me to the line...

http.open('get', '/_ajax/AJAX_display_emp_profile_info.php');


I am wondering if it can't refresh the area that is making the call
for some reason. I'm new to the whole Asynchronous connection, so I
may be way off. Any guidance is appreciated.

Thanks,
D.
 
D

DonO

DonO said the following on 11/19/2007 6:12 PM:






IE7 supports XMLHttpRequest(). No need for the navigator code at all.

Is there a sample URL that displays the behavior?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

It's on an intranet with IE 6 as the standard (for now). I have been
reading through the jibbering site for some hints. Great resource.
Thanks for posting.
 
D

DonO

I found a work around for me. May not be the best way to do it, but it
seems to work in IE 6 and FF 2.x

I had this...

http.onreadystatechange = function (){
build_employee_info();
}

In my original code, which worked for FF but not IE. I now have
this...

http.onreadystatechange = function (){
if(navigator.appName == "Microsoft Internet Explorer"){
// ie updates through separate function
updateSite();
}
else {
// ff updates directly
build_employee_info();
}
}

I added a function for IE that checks readystate. I don't know why FF
doesn't work with this as well...

function updateSite(){
if(http.readystate == 4){
build_employee_info();
}
}

Sooo... I'm moving on to other issues. Maybe as I learn more about
this stuff it will seem obvious to me, but for now, a work around will
have to do for me. Hope it helps someone else.

Thanks
 
G

Gregor Kofler

DonO meinte:
I found a work around for me. May not be the best way to do it, but it
seems to work in IE 6 and FF 2.x

I had this...

http.onreadystatechange = function (){
build_employee_info();
}

In my original code, which worked for FF but not IE. I now have
this...

http.onreadystatechange = function (){
if(navigator.appName == "Microsoft Internet Explorer"){
// ie updates through separate function
updateSite();
}
else {
// ff updates directly

Nope. It doesn't. In all browser you have to check for the proper
readyState (and the status of the delivered data, too).
build_employee_info();
}
}

I added a function for IE that checks readystate. I don't know why FF
doesn't work with this as well...

function updateSite(){
if(http.readystate == 4){
build_employee_info();
}
}

Perhaps because it is "readyState" and not "readystate"?
Sooo... I'm moving on to other issues. Maybe as I learn more about
this stuff it will seem obvious to me, but for now, a work around will
have to do for me. Hope it helps someone else.

Definitely not. Since all those AJAX libraries out there check for the
proper readyState and - I suppose - work on all contemporary browsers
without some outdated browser sniffing.

You're welcome.

Gregor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top