...

View Full Version : Js (ajax) Problem In Ie



michaelespinosa
10-12-2007, 07:40 PM
I am building a page for a school that will allow students to listen to there classes online. I did this using by having a page that has a list of the classes and when you click on one of the classes it uses js to load and external file into the current page. It works pretty good in all browsers except IE. It's shows Loading... but never finishes the request.

Here's (http://www.trsom.com/students/first_year/fall/a.php) the page I'm talking about.

Heres the JS
Inline link:

<a href="javascript:player('files/bt_1.php','player');">Week 1</a>
Linked JS:

function player(url,target) {
// native XMLHttpRequest object
document.getElementById(target).innerHTML = "Loading...";
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = function() {jahDone(target);};
req.open("GET", url, true);
req.send(null);
// IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = function() {jahDone(target);};
req.open("GET", url, true);
req.send();
}
}
}

function jahDone(target) {
// only if req is "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
results = req.responseText;
document.getElementById(target).innerHTML = results;
} else {
document.getElementById(target).innerHTML="audio error:\n" +
req.statusText;
}
}
}

nikkiH
10-13-2007, 12:12 AM
Have you tried debugging by adding "else" to those 2 ifs with an alert to see what is firing?

michaelespinosa
10-13-2007, 12:36 AM
Thanks nikkiH, I am kind of new with js(ajax). Would you be kind enough to show me how to debug it. I tried but not sure I'm doing it right. I believe the

else if (window.ActiveXObject)
is not firing though, because the loading image pops up but it doesn't bring the requested file in though.

Thanks

michaelespinosa
10-13-2007, 02:41 AM
Ok I have now tried to switch to this example (http://bulletproofajax.com/code/chapter06/loading/people/index.php) via jeremy keith. I am getting the same results; works great in every browser except IE. My gosh what I am missing I've searched online and tried various solutions but to no avail. Please help!

Check it out on my page (http://www.trsom.com/students/first_year/fall/a.php).

rwedge
10-14-2007, 07:44 PM
You have a local scope on the variable xhr in your getHTTPObject function


function getHTTPObject() {
var xhr = false;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
xhr = false;
}
}
}
return xhr;
}

try changing the scope to global


var xhr = false;
function getHTTPObject() {
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
xhr = false;
}
}
}
return xhr;
}

michaelespinosa
10-15-2007, 03:46 AM
rwedge I gave that a shot but to no avail. It still isn't working. I am at a loss at this point. PLEASE does anybody have any other ideas?

A1ien51
10-15-2007, 04:04 AM
Change the paragraph tag <p> to a div <div> tag and see if your error goes away.

edit [I am talking about the paragraph tag where you are outputting the data. aka "player"]

Eric

nikkiH
10-15-2007, 02:48 PM
I get "unknown runtime error" in IE. I doubt I have RealPlayer installed on this computer (work).

That said, try adding alerts in here so you can see which object is returned:


function getHTTPObject() {
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
alert("XMLHttpRequest");
} else if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
alert("Msxml2");
} catch(e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
alert("Microsoft");
} catch(e) {
xhr = false;
}
}
}
return xhr;
}

And add a try / catch in grabFile function - if an exception is caught, alert it so you can see what happened.

A1ien51
10-15-2007, 03:59 PM
The problem is what I mentioned. It has nothing to do with the Ajax call. You can not set the innerHTML of a paragraph tag that contains a div with IE6.

Eric

michaelespinosa
10-15-2007, 05:08 PM
A1ien51 thank you so much for the enlightenment. I shouldn't of had a div inside a paragraph anyways. Also thanks to everyone who made suggestions.

Thanks
Michael



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum