XMLHTTP object and client-side include

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fabri

    #1

    XMLHTTP object and client-side include

    I'm trying to develop a way to include static files in htm pages with
    javascript.

    I'm trying to use XMLHTTP object this way:

    ----------------------------------------------------------------------

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>XMLHTT P</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">

    var xmlhttp=false;

    try {
    xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
    } catch (e) {
    try {
    xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
    } catch (E) {
    xmlhttp = false;
    }
    }

    if (!xmlhttp && typeof XMLHttpRequest! ='undefined') {
    xmlhttp = new XMLHttpRequest( );
    }

    function include(xUrl,xI d){
    xmlhttp.open("G ET", xUrl,true);
    xmlhttp.onready statechange=fun ction() {
    if (xmlhttp.readyS tate==4) {
    document.getEle mentById(xId).i nnerHTML = xmlhttp.respons eText;
    }
    }
    xmlhttp.send(nu ll)
    }

    </script>
    </head>
    <body>
    <script type="text/javascript">
    include("header .htm", "xheader");
    </script>
    <div id="xheader"></div>
    <hr>Corpo<hr>
    <div id="xfooter"></div>
    <script type="text/javascript">
    include("footer .htm", "xfooter");
    </script>
    </body>
    </html>

    ----------------------------------------------------------------------


    header.htm and footer.htm are html examples files.

    It doesn't work if I call header and footer but if I call only header it
    works.


    Any help much appreciated.

    Best Regards.


    --
    Fabri
    (Non è tuttu oru chiddu chi stralluci, né tuttu veru chiddu ca si dici)
  • Martin!

    #2
    Re: XMLHTTP object and client-side include

    Fabri wrote:
    [color=blue]
    > I'm trying to develop a way to include static files in htm pages with
    > javascript.
    >
    > I'm trying to use XMLHTTP object this way:
    >
    > ----------------------------------------------------------------------
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    > <html>
    > <head>
    > <title>XMLHTT P</title>
    > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    > <script type="text/javascript">
    >
    > var xmlhttp=false;
    >
    > try {
    > xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
    > } catch (e) {
    > try {
    > xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
    > } catch (E) {
    > xmlhttp = false;
    > }
    > }
    >
    > if (!xmlhttp && typeof XMLHttpRequest! ='undefined') {
    > xmlhttp = new XMLHttpRequest( );
    > }
    >
    > function include(xUrl,xI d){
    > xmlhttp.open("G ET", xUrl,true);
    > xmlhttp.onready statechange=fun ction() {
    > if (xmlhttp.readyS tate==4) {
    > document.getEle mentById(xId).i nnerHTML =
    > xmlhttp.respons eText;
    > }
    > }
    > xmlhttp.send(nu ll)
    > }
    >
    > </script>
    > </head>
    > <body>
    > <script type="text/javascript">
    > include("header .htm", "xheader");
    > </script>
    > <div id="xheader"></div>
    > <hr>Corpo<hr>
    > <div id="xfooter"></div>
    > <script type="text/javascript">
    > include("footer .htm", "xfooter");
    > </script>
    > </body>
    > </html>
    >
    > ----------------------------------------------------------------------
    >
    >
    > header.htm and footer.htm are html examples files.
    >
    > It doesn't work if I call header and footer but if I call only header it
    > works.
    >
    >
    > Any help much appreciated.
    >
    > Best Regards.
    >
    >[/color]


    why not simply use Server Side Include, or the php equivalent ?

    Comment

    • Fabri

      #3
      Re: XMLHTTP object and client-side include

      Martin! wrote:
      [color=blue]
      > why not simply use Server Side Include, or the php equivalent ?[/color]


      Because on my hosting-server they are not supported.

      --
      Fabri
      (Non è tuttu oru chiddu chi stralluci, né tuttu veru chiddu ca si dici)

      Comment

      • Cenekemoi

        #4
        Re: XMLHTTP object and client-side include

        Bonjour à Fabri <no@sp.am> qui nous a écrit :[color=blue]
        > [...]
        > function include(xUrl,xI d){
        > xmlhttp.open("G ET", xUrl,true);
        > xmlhttp.onready statechange=fun ction() {
        > if (xmlhttp.readyS tate==4) {
        > document.getEle mentById(xId).i nnerHTML = xmlhttp.respons eText;
        > }
        > }
        > xmlhttp.send(nu ll)
        > }
        >
        > </script>
        > </head>
        > <body>
        > <script type="text/javascript">
        > include("header .htm", "xheader");
        > </script>
        > <div id="xheader"></div>
        > <hr>Corpo<hr>
        > <div id="xfooter"></div>
        > <script type="text/javascript">
        > include("footer .htm", "xfooter");
        > </script>
        > </body>
        > </html>
        > [...][/color]

        be carefull, you must place "div" tag before the script, ie :

        ...
        <div id="xheader"></div>
        <script type="text/javascript">
        include("header .htm", "xheader");
        </script>
        ...

        --
        Cordialement, Thierry ;-)

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: XMLHTTP object and client-side include

          Fabri wrote:
          [color=blue]
          > Martin! wrote:[color=green]
          >> why not simply use Server Side Include, or the php equivalent ?[/color]
          >
          > Because on my hosting-server they are not supported.[/color]

          Then you should switch ASAP to another service provider or wait for, hm,
          another year to get XMLHTTPRequest widely implemented. And then it is
          likely that you have a Web where exploits let emerge UAs where this single
          feature, short of disabling client-side scripting completely or not even
          have it supported in the first place, can be disabled. Fortunately,
          hosting prices would have dropped by then as well.

          BTW: Your sender address is forged which violates/disregards Internet
          standards, most certainly the Acceptable Use Policy of your Usenet access
          provider (NGI S.p.A.) and Netiquette. Change this ASAP or prepare to face
          the consequences.


          PointedEars
          --
          Der Beweis ist ein Götze, vor dem der Mathematiker sich foltert.
          -- Sir Arthur Stanley Eddington (1882-1944)

          Comment

          • Randy Webb

            #6
            Re: XMLHTTP object and client-side include

            Thomas 'PointedEars' Lahn wrote:[color=blue]
            > Fabri wrote:
            >
            >[color=green]
            >>Martin! wrote:
            >>[color=darkred]
            >>>why not simply use Server Side Include, or the php equivalent ?[/color]
            >>
            >>Because on my hosting-server they are not supported.[/color]
            >
            >
            > Then you should switch ASAP to another service provider or wait for, hm,
            > another year to get XMLHTTPRequest widely implemented.[/color]

            It is supported in perhaps 90% of browsers on the web, how much more
            "widely" do you want it implemented?

            <snip>
            [color=blue]
            > BTW: Your sender address is forged which violates/disregards Internet
            > standards, most certainly the Acceptable Use Policy of your Usenet access
            > provider (NGI S.p.A.) and Netiquette. Change this ASAP or prepare to face
            > the consequences.[/color]

            Please tell me we are not going to go through this childish juvenile
            bullshit again about email addresses?

            --
            Randy
            comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

            Comment

            • Matthew Lock

              #7
              Re: XMLHTTP object and client-side include

              You could also consider using iframes. They have their own set of
              issues, but they are simple to implement.

              Comment

              • kaeli

                #8
                Re: XMLHTTP object and client-side include

                In article <2LadncEm9ocSpc bfRVn-uQ@comcast.com> , HikksNotAtHome@ aol.com
                enlightened us with...[color=blue]
                >
                > Please tell me we are not going to go through this childish juvenile
                > bullshit again about email addresses?[/color]

                His childish bullshit about email addresses and attributions is why he's one
                of only two people in my killfile. He spends more time going on about what
                other people did wrong in their postings than any other topic. It negates the
                useful stuff he posts.

                Some people need to learn that they aren't the 'net police. Until they do, I
                don't need to take up my valuable time reading their crap.

                / wishes there was a way to kill responses to this shit without killfiling
                the people relying...

                --
                --
                ~kaeli~
                If a turtle doesn't have a shell, is he homeless or naked?



                Comment

                Working...