SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2004
    Posts
    419
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I call 4 functions at once when a page loads?

    I am working on a web page which has 4 ajax areas in it. Three return images, and 1 returns news content.

    http://jimpix.co.uk/default-ajax1.asp

    The javascript for each function is initialised by this javascript function:

    Code JavaScript:
    window.onload = function()
    {
        sendRequest(MyCurrentVar + ',' + MyCurrentCat)
        sendPhotoRequest(MyPhotoVar)
        sendNewsRequest(MyNewsVar)
        sendWPRequest(MyWPVar)
    }

    When I first view the page, none of the Ajax content appears (Firefox or IE6).

    It only appears if I click one of the next / prev links.

    If I only have the 1 function being called in the window.onload function, then the relevant content appears.

    Just wondered if there is any way I can "initialise", or whatever it's called, 4 functions at the same time when the page loads.

    Any help much appreciated!

    Thank you

  2. #2
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the error console show any errors? (also HUGE deja vu on this one :hmm

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2004
    Posts
    419
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I know I have posted 3 messages now about this same error, all very similar. On the last one, I posted the message, but because I hadn't uploaded the test page, it returned a 404 error. When I updated the message to say I had corrected it, it didn't get a reply, so I raised a new message, slightly different to the last one.

    Sorry.

    Yes, I had forgotten to check the error console. It says:

    Error: uncaught exception: [Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send]" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: http://jimpix.co.uk/default-ajax1.asp :: sendNewsRequest :: line 313" data: no]

    Thanks

    Jim

  4. #4
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sending AJAX requests to the same hostname as the HTML file making the requests?

  5. #5
    SitePoint Evangelist
    Join Date
    Dec 2004
    Posts
    419
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just hunting around on google, seems my initial function was wrong, so I have changed it to:

    Code JavaScript:
    //function createRequestObject() {
    //    var ro;
    //    if (navigator.appName == "Microsoft Internet Explorer") {
    //        ro = new ActiveXObject("Microsoft.XMLHTTP");
    //    } else {
    //        ro = new XMLHttpRequest();
    //    }
    //    return ro;
    //}
    //var http = createRequestObject();
     
    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 http = GetXmlHttpObject();

    That almost fixes things. Now I don't get any console errors. All looks fine in Firefox. BUT, this page:

    http://jimpix.co.uk/default-ajax1.asp

    Only displays the wallpaper ajax content on first loading when viewed in IE6, and ignores all of the others!

    I ended up trying this method to load the 4 functions when loading the page up:
    http://www.netlobo.com/wom.html

    But it still doesn't work in IE6.

    Thanks

  6. #6
    SitePoint Evangelist
    Join Date
    Dec 2004
    Posts
    419
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to sound impatient. Just "Bumping" this up the list again, instead of starting a new thread, since that is not so polite. Thank you!


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
  •