SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot XandroZ's Avatar
    Join Date
    May 2006
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ajax not working in IE

    I try to learn Ajax so I start with a simple page; i parse a text from a file.It is working in FF but not in IE.I use catch and try method of creating an instance of the object, until one such method succeeds.I try also with window.*** but not working
    java script
    Code:
    function getXMLHTTPRequest()
    {
    var request = false;
    try
      {
        request = new XMLHttpRequest(); // Firefox
      }
    catch(err1)
      {
      try
        {
        request = new ActiveXObject("Msxml2.XMLHTTP");
      // IE new
        }
      catch(err2)
        {
        try
          {
          request = new ActiveXObject("Microsoft.XMLHTTP");
    //Ie old
          }
          catch(err3)
            {
            request = false;
            }
        }
      }
    return request;
    }
    
    /////////////////////////////
    var myreq = getXMLHTTPRequest();
    
    function callAjax(){
    if(myreq) {
    var url = "vsl.txt";
    myreq.open("GET", url);
    myreq.onreadystatechange = function()
    {
    if (myreq.readyState == 4 && myreq.status == 200) {
    document.getElementById("tara").innerHTML =myreq.responseText;
    }
    }
    myreq.send(null);
    }
    }
    HTML
    Code:
    <div id="tara"></div>
    
    <div id="Layer1">
      <input type="button" name="Button" value="Button" onclick="callAjax()"/>

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My suggestion is to use the jQuery library to do Ajax instead of coding the individual functions yourself. You can download it here and there is decent documentation here.

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IE won't handle this line properly:
    Code:
    if (myreq.readyState == 4 && myreq.status == 200) {
    You need to split up the ifs:
    Code:
    if (myreq.readyState == 4) {
    	if (myreq.status == 200) {

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about

    Code:
    if ((myreq.readyState == 4) && (myreq.status == 200)) {
    I've used this many times (well not with these particular conditionals, but the same structure) and it seems to work fine...

    Dave

  5. #5
    SitePoint Zealot XandroZ's Avatar
    Join Date
    May 2006
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I resolved the problem.The code is good i tested on another computer.
    Is something wrong with my IE and I will reinstal.


Bookmarks

Posting Permissions

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