Ajax Script - works in Firefox, not in IE6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • burtonfigg
    New Member
    • Mar 2008
    • 32

    Ajax Script - works in Firefox, not in IE6

    I'm testing an ajax page - this works fine in Firefox:
    Use the jimpix username generator to create unique and memorable usernames for Instagram, Twitter, Youtube and popular social media sites


    Click on any of the links on the right under the 'occassions' or 'others' headings, in Firefox, and thumbnails appear based on what you clicked on.

    Do the same in IE6, and it returns an error:

    Line: 71
    Char: 9
    Error: Unknown runtime error


    This relates to this line:

    Code:
    <p class="ctr"><span id="my_photo_id_label"></span></p>
    The error happens as soon as the page is loaded, before I even click a link.

    This is the javascript on the page:

    Code:
    function addLoadEvent(func) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function() {
                if (oldonload) {
                    oldonload();
                }
                func();
            }
        }
    }
    
    function GetXmlHttpObject() {
      var xmlhttp;
      if (window.XMLHttpRequest) { // Mozilla, Safari, Opera...
        xmlhttp = new XMLHttpRequest();
        //if (xmlhttp.overrideMimeType) xmlhttp.overrideMimeType('text/xml');
      } else if (window.ActiveXObject) { // IE
          try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
              try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
              } catch (e) {}
          }
      }
      if (!xmlhttp) {
        alert('Cannot create an XMLHTTP instance');
        return false;
      }
      return xmlhttp;
    }
    
    var ec = GetXmlHttpObject();
    
    function sendMyPhotoRequest(id) {
        ec.open('get', '../ajax/ajax-ec.asp?id=' + encodeURIComponent(id));
        ec.onreadystatechange = handleMyPhotoResponse;
        ec.send(null);
    }
    
    function handleMyPhotoResponse() {
    	// If everything is okay:
        if(ec.readyState == 4){
        	// Assign the returned value to the document object.
            document.getElementById('my_photo_id_label').innerHTML = ec.responseText;
        }
    }
    
    addLoadEvent(function() {
        sendMyPhotoRequest(44);
    })
    The plan was to click a hyperlink on the right, and then send a variable to the 'ajax-ec.asp' page, via this syntax:

    Code:
    <li><a href= "#pop" onclick="sendMyPhotoRequest(45);">Various</a></li>
    Not sure why it would work for Firefox, but not IE6.

    I tested on another page:
    Use the jimpix username generator to create unique and memorable usernames for Instagram, Twitter, Youtube and popular social media sites


    And this works in IE6, even though the Javascript is v. similar.

    But instead of passing the variable as a number as above, the hyperlink is as follows:

    Code:
    <a title="" href="#pc" onclick="sendPhotoRequest(next_photo());">Next</a>
    And the function initialising the page is:

    Code:
    addLoadEvent(function() {
        sendPhotoRequest(MyPhotoVar);
    })
    Where MyPhotoVar is initialised as:

    Code:
    var MyPhotoVar = 0;
    Is that the problem - that I can't send numbers via the functions, but need to use a variable instead?

    I'm sorry for:

    1. Going on for so long
    2. Not knowing what I'm doing
    3. Talking a load of rubbish

    Thanks
  • burtonfigg
    New Member
    • Mar 2008
    • 32

    #2
    Fixed it. Sorry to waste anyones time.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Originally posted by burtonfigg
      Fixed it. Sorry to waste anyones time.
      Care to post how you solved this problem? It may help others.

      Cheers.

      Comment

      Working...