Javascript program not being called

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

    Javascript program not being called

    I have a web page that attempts to call a piece of Javascript, which
    attempts to transform an xml file and an xslt file into Html.

    The call is here (A) :

    <script language = "JavaScript " src = "customfeed.htm l?Ga_Id=36475"
    type="text/javascript"></script>

    The script is here (B) :

    <script language = "JavaScript " type = "text/javascript">
    var dataArray = new Array();
    var querystring = window.location .href;
    dataArray = window.location .href.split("=" );
    for (j=0;j<dataArra y.length;j++)
    {
    eval(dataArray[j])
    }
    theXML = new ActiveXObject(" Microsoft.XMLDO M");
    theXML.async=fa lse;
    theXML.load("xm lfeed.asp?Ga_Id =" + eval(dataArray[1]) );
    theXSL = new ActiveXObject(" Microsoft.XMLDO M");
    theXSL.async = false;
    theXSL.load("st ylesheet01.asp? Ga_Id=" + eval(dataArray[1]) );
    document.write( theXML.transfor mNode(theXSL));
    </script>

    When viewing source on the page, I get (A) instead of what I would expect,
    which is an Html table created in the xslt file, and populated with data
    from the xml file. Both files have asp extensions as they use asp code. I
    have tried to run this script as an html file, it runs in isolation, but not
    when called.

    Any help would be appreciated

    John


  • Mark Tranchant

    #2
    Re: Javascript program not being called

    John D wrote:
    [color=blue]
    > I have a web page that attempts to call a piece of Javascript, which
    > attempts to transform an xml file and an xslt file into Html.
    >
    > The call is here (A) :
    >
    > <script language = "JavaScript " src = "customfeed.htm l?Ga_Id=36475"
    > type="text/javascript"></script>[/color]

    Are you allowed spaces around the equal signs in HTML?

    You may be having media type problems. Put the JS source in a .js file,
    and set the type in the script attribute:

    <script type="text/javascript" src="..."></script>

    The validator would probably have told you most of that.

    --
    Mark.

    Comment

    • John D

      #3
      Re: Javascript program not being called

      > > I have a web page that attempts to call a piece of Javascript, which[color=blue][color=green]
      > > attempts to transform an xml file and an xslt file into Html.[/color]
      > The validator would probably have told you most of that[/color]

      Thanks for the reply

      Is this a JavaScript validator? If so can you point me in that direction?

      John


      Comment

      • SpaceGirl

        #4
        Re: Javascript program not being called

        John D wrote:
        [color=blue][color=green][color=darkred]
        >>>I have a web page that attempts to call a piece of Javascript, which
        >>>attempts to transform an xml file and an xslt file into Html.[/color]
        >>
        >>The validator would probably have told you most of that[/color]
        >
        >
        > Thanks for the reply
        >
        > Is this a JavaScript validator? If so can you point me in that direction?
        >
        > John
        >
        >[/color]


        language = "JavaScript "

        That's not needed at all.

        --


        x theSpaceGirl (miranda)

        # lead designer @ http://www.dhnewmedia.com #
        # remove NO SPAM to email, or use form on website #

        Comment

        • John D

          #5
          Re: Javascript program not being called

          > > <script language = "JavaScript " src = "customfeed.htm l?Ga_Id=36475"[color=blue][color=green]
          > > type="text/javascript"></script>[/color]
          > You may be having media type problems. Put the JS source in a .js file,
          > and set the type in the script attribute:
          >
          > <script type="text/javascript" src="..."></script>
          >[/color]

          Just tried putting the JS source in a .js file and there were no changes to
          how the pages behave.

          Confused you will be, after this episode of .....

          John


          Comment

          • Lee

            #6
            Re: Javascript program not being called

            John D said:
            [color=blue]
            >The call is here (A) :
            >
            ><script language = "JavaScript " src = "customfeed.htm l?Ga_Id=36475"
            >type="text/javascript"></script>
            >
            >The script is here (B) :
            >
            > <script language = "JavaScript " type = "text/javascript">[/color]
            ....[color=blue]
            > </script>[/color]

            That's not Javascript, that's HTML.
            Get rid of the <script></script> HTML tags and it will be Javascript.

            Comment

            • Mark Tranchant

              #7
              Re: Javascript program not being called

              John D wrote:
              [color=blue][color=green][color=darkred]
              >>>I have a web page that attempts to call a piece of Javascript, which
              >>>attempts to transform an xml file and an xslt file into Html.[/color]
              >>
              >>The validator would probably have told you most of that[/color]
              >
              >
              > Thanks for the reply
              >
              > Is this a JavaScript validator? If so can you point me in that direction?[/color]

              No. I don't *think* your problem is Javascript related at this point.
              I'm talking about the W3C HTML validator.

              W3C's easy-to-use markup validation service, based on SGML and XML parsers.


              As a simple check, put an alert box right at the top of your Javascript
              code:

              alert("This code is working!");

              If you don't see it, then the problem is in the calling of the
              Javascript, not the execution.

              --
              Mark.

              Comment

              • John D

                #8
                Re: Javascript program not being called

                > >>>I have a web page that attempts to call a piece of Javascript, which[color=blue][color=green][color=darkred]
                > >>>attempts to transform an xml file and an xslt file into Html.[/color][/color]
                > If you don't see it, then the problem is in the calling of the
                > Javascript, not the execution.[/color]

                We did this and we don't see it.
                So yes this is the calling that is the problem.

                Any idea what is wrong with the way we call the JS?

                John


                Comment

                • John D

                  #9
                  Re: Javascript program not being called

                  [color=blue][color=green]
                  > ><script language = "JavaScript " src = "customfeed.htm l?Ga_Id=36475"
                  > >type="text/javascript"></script>
                  > >
                  > >The script is here (B) :
                  > >
                  > > <script language = "JavaScript " type = "text/javascript">[/color]
                  > ...[color=green]
                  > > </script>[/color]
                  >
                  > That's not Javascript, that's HTML.
                  > Get rid of the <script></script> HTML tags and it will be Javascript.
                  >[/color]

                  We did that but it does not make it work.
                  Boy, are we scratching our heads on this one!

                  John


                  Comment

                  • Brian

                    #10
                    Re: Javascript program not being called

                    John D wrote:
                    [color=blue]
                    > this is the calling that is the problem.
                    >
                    > Any idea what is wrong with the way we call the JS?[/color]

                    Have you validated your html yet?

                    [Since this seems to have nothing to do with XML, I've trimmed xposted
                    groups.]

                    --
                    Brian (remove ".invalid" to email me)

                    Comment

                    • Mark Tranchant

                      #11
                      Re: Javascript program not being called

                      John D wrote:
                      [color=blue][color=green][color=darkred]
                      >>>>>I have a web page that attempts to call a piece of Javascript, which
                      >>>>>attempts to transform an xml file and an xslt file into Html.[/color]
                      >>
                      >>If you don't see it, then the problem is in the calling of the
                      >>Javascript, not the execution.[/color]
                      >
                      >
                      > We did this and we don't see it.
                      > So yes this is the calling that is the problem.
                      >
                      > Any idea what is wrong with the way we call the JS?[/color]

                      Don't use the query string, and put the JS in a true JS file, not a
                      <script>-enclosed HTML file.

                      In the HTML:

                      <script type="text/javascript" src="blah.js"></script>
                      <script type="text/javascript">
                      customfeed("364 75");
                      </script>

                      and in blah.js:

                      function customfeed(var querystring) {
                      (all your code)
                      }

                      --
                      Mark.

                      Comment

                      • Richard Cornford

                        #12
                        Re: Javascript program not being called

                        Mark Tranchant wrote:
                        <snip>[color=blue][color=green]
                        >> <script language = "JavaScript " src = "customfeed.htm l?Ga_Id=36475"
                        >> type="text/javascript"></script>[/color]
                        >
                        > Are you allowed spaces around the equal signs in HTML?[/color]

                        Yes, but most people don't use spaces in that context because they are a
                        waste of bandwidth and actually detract from readability in the HTML
                        code (they make it difficult to see where one attribute ends and the
                        next starts).
                        [color=blue]
                        > You may be having media type problems.[/color]

                        Unlikely as javascript has no official MIME type so browsers disregard
                        content-type headers sent with resources referred to by the SRC
                        attributes of SCRIPT elements. And they tend to assume that a script is
                        javascript if not given any positive reason to think otherwise (though
                        in this case the TYPE attribute leaves the browser in no doubt).
                        [color=blue]
                        > Put the JS source in a .js file,[/color]

                        File extensions on javascript source files are not significant, any
                        valid URL will do so long as the contents are javascript source code. A
                        dot-html extension is a perverse choice (and will cause maintenance
                        problems later) but completely legal and valid.
                        [color=blue]
                        > and set the type in the script attribute:[/color]

                        There already is a TYPE attribute in the SCRIPT element. But it's
                        presence does makes the deprecated LANGUAGE attribute redundant.
                        [color=blue]
                        > <script type="text/javascript" src="..."></script>
                        >
                        > The validator would probably have told you most of that.[/color]

                        If the DOCTYPE was HTML 4.01 transitional then the SCRIPT element was
                        already valid.

                        Richard.


                        Comment

                        • Richard Cornford

                          #13
                          Re: Javascript program not being called

                          John D wrote:
                          <snip>[color=blue]
                          > <script language = "JavaScript " type = "text/javascript">
                          > var dataArray = new Array();
                          > var querystring = window.location .href;[/color]

                          location.href will return a string that represents an absolute URL, that
                          may have an appended query string. Say something along the lines of:-


                          [color=blue]
                          > dataArray = window.location .href.split("=" );[/color]

                          And it still represents the same absolute URL when you read it again
                          here.

                          But now you split it into a two element array of strings along the lines
                          of:-

                          ["http://example.com/page.asp?someth ing", "data"]
                          [color=blue]
                          > for (j=0;j<dataArra y.length;j++)
                          > {
                          > eval(dataArray[j])[/color]
                          <snip>

                          And now you have executed the string that is held in the first element
                          of that array as javascript source code. i.e. you have executed
                          "http://example.com/page.asp?someth ing", which is: a label, a division
                          operator, a regular expression literal, a property accessor, part of a
                          conditional operation and an identifier (in other words, one big syntax
                          error).

                          It is often said that the use of - eval - is never necessary anyway, but
                          that one of the many good reasons for not using it is that it masks
                          errors.

                          Generally it has got to make more sense in the long run to only employ
                          people who understand javascript to write javascript.

                          Richard.


                          Comment

                          • John D

                            #14
                            Re: Javascript program not being called

                            > It is often said that the use of - eval - is never necessary anyway, but[color=blue]
                            > that one of the many good reasons for not using it is that it masks
                            > errors.[/color]

                            So is what you are saying that when we test the script from a browser the
                            eval, even though there is a problem, still displays the feed.

                            but when the script is called from another page the eval still fails but
                            nothing is returned

                            Do you know a JavaScript way of retrieving QueryString related data?

                            Any help appreciated.

                            John

                            P.S. the fellow I am asking this for says "heh, hands up I copied it from
                            the site of a so called JavaScript expert!!!"


                            Comment

                            • sma1king

                              #15
                              Re: Javascript program not being called

                              "John D" <dobjsonneNOSPA Mhotmail.com> wrote in message
                              news:40e16b37$0 $288$ed9e5944@r eading.news.pip ex.net...[color=blue]
                              > I have a web page that attempts to call a piece of Javascript, which
                              > attempts to transform an xml file and an xslt file into Html.
                              >
                              > The call is here (A) :
                              >
                              > <script language = "JavaScript " src = "customfeed.htm l?Ga_Id=36475"
                              > type="text/javascript"></script>
                              >
                              > The script is here (B) :
                              >
                              > <script language = "JavaScript " type = "text/javascript">
                              > var dataArray = new Array();
                              > var querystring = window.location .href;
                              > dataArray = window.location .href.split("=" );
                              > for (j=0;j<dataArra y.length;j++)
                              > {
                              > eval(dataArray[j])
                              > }
                              > theXML = new ActiveXObject(" Microsoft.XMLDO M");
                              > theXML.async=fa lse;
                              > theXML.load("xm lfeed.asp?Ga_Id =" + eval(dataArray[1]) );
                              > theXSL = new ActiveXObject(" Microsoft.XMLDO M");
                              > theXSL.async = false;
                              > theXSL.load("st ylesheet01.asp? Ga_Id=" + eval(dataArray[1]) );
                              > document.write( theXML.transfor mNode(theXSL));
                              > </script>
                              >
                              > When viewing source on the page, I get (A) instead of what I would expect,
                              > which is an Html table created in the xslt file, and populated with data
                              > from the xml file. Both files have asp extensions as they use asp code.[/color]
                              I[color=blue]
                              > have tried to run this script as an html file, it runs in isolation, but[/color]
                              not[color=blue]
                              > when called.
                              >
                              > Any help would be appreciated
                              >
                              > John
                              >
                              >[/color]
                              John,

                              Where is the <script> located in your HTML page? head? body?

                              George


                              Comment

                              Working...