SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Mexico
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Onload vs. SRC method

    So I been playing around with the way to invoke data froma different server. However I had this issue where I tried to load the data from:
    <body onload="include('http://192.168.2.../file.txt');">
    And didn't work however when I a script href="http://.../file.js" it works, can someone tell me why the first one didn't?

    According to this tutorial both methods are valid:

    Our JavaScript calls a function which uses the remote scripting object to get the file at the URL given. The file is simply returned to us as a string of characters, which are loaded into an HTML division. The string returned could be placed in nearly any HTML container or simply written to the browser window using a document.write command. To call the function is simple;
    Calling include() With The Onload Event
    <body onload="include('http://www.ourdomain.com/path/filename.txt');">

    In the example we use the body onload event to execute the include(URL) command.
    and later on:
    Besides, we can do it as simply as a Server Side Include...thus.
    A JavaScript Include
    <script>include('thePage.htm','elementId');</script>

    Simply add one line to the head of your page to enable the include function.
    Just Add One Line To The Head Section
    <script type="text/javascript" src="include.js"></script>

    A live example of the simple client side include function
    Alexandro Colorado

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems that the path is escaping its self. If you double all slashes it should work ok.

    Code:
    <body onload="include('http:////www.ourdomain.com//path//filename.txt');">
    edit: Although i've just copied in their code into a document, and it worked without needing to double all slashes.

    When you say it didn't work? Do you see this result on both IE and Firefox? If so, can you see what Firefox's Error Console or Javascript Console displays? Is there even any error messages? Could it be that the file your trying to view doesn't exist?

    change your postFileReady function for this
    Code:
            function postFileReady() {
                alert('Ready State: ' + xmlhttp.readyState + '\nHTTP Status: ' + xmlhttp.status);
               if (xmlhttp.readyState==4) {
                  if (xmlhttp.status==200) {
                     document.getElementById('theDivToLoad').innerHTML=xmlhttp.responseText;
                  }
               }
            }
    And if you can, make a note of each alert window that appears.



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
  •