Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    69
    Thanks
    11
    Thanked 2 Times in 2 Posts

    Js (ajax) Problem In Ie

    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 the page I'm talking about.

    Heres the JS
    Inline link:
    Code:
    <a href="javascript:player('files/bt_1.php','player');">Week 1</a>
    Linked JS:
    Code:
    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;
    		}
    	}
    }
    Last edited by michaelespinosa; 10-12-2007 at 10:44 PM. Reason: sp error

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Have you tried debugging by adding "else" to those 2 ifs with an alert to see what is firing?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    69
    Thanks
    11
    Thanked 2 Times in 2 Posts
    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
    Code:
    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

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    69
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Ok I have now tried to switch to this example 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.
    Last edited by michaelespinosa; 10-13-2007 at 05:02 AM.

  • #5
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    You have a local scope on the variable xhr in your getHTTPObject function

    Code:
    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

    Code:
    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;
    }

  • #6
    New Coder
    Join Date
    Aug 2007
    Posts
    69
    Thanks
    11
    Thanked 2 Times in 2 Posts
    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?

  • #7
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    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
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #8
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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:

    Code:
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #9
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    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
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • The Following 2 Users Say Thank You to A1ien51 For This Useful Post:

    Basscyst (10-16-2007), michaelespinosa (10-15-2007)

  • #10
    New Coder
    Join Date
    Aug 2007
    Posts
    69
    Thanks
    11
    Thanked 2 Times in 2 Posts
    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


  •  

    Posting Permissions

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