Problem posting form to an IFrame

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

    Problem posting form to an IFrame

    I have a rather complicated business application that uses Ajax. Part
    of this form requires uploading documents, which I cannot do using
    Ajax, so I post the form to an IFrame. This part works just fine.

    The problem I have is that my server process returns some content to
    the IFrame to complete form processing and to report any errors that
    might have occured. Here's an example of what may be written back:

    <html>
    <head>
    <script type="text/javascript">
    function completed() {
    window.parent.r eportsCompleted ();
    }
    </script>
    <body onload="complet ed();">
    <error>The document type .doc is not supported.</error>
    </body>
    </html>

    Now this does properly call the reportsComplete d method of the parent
    frame. The problem I am having is reading the contents of any <error>
    tags if they exist:

    function reportsComplete d() {
    var frame = frames['upload_frame'];
    if (frame.document .getElementsByT agName("error") .length 0) { //
    there were errors...
    var message = "The following error(s) occured:";
    for (var i = 0; i <
    frame.document. getElementsByTa gName("error"). length; i++) {
    message += "\n" +
    frame.document. getElementsByTa gName("error")[i].nodeValue();
    }
    alert(message);
    }
    }

    The problem is that I never get the contents of the error tags
    displayed. I only see an alert window that says "The following
    error(s) occured:".

    What am I doing wrong?
  • RoLo

    #2
    Re: Problem posting form to an IFrame

    On Apr 16, 3:30 pm, Tom Cole <tco...@gmail.c omwrote:
    I have a rather complicated business application that uses Ajax. Part
    of this form requires uploading documents, which I cannot do using
    Ajax, so I post the form to an IFrame. This part works just fine.
    >
    The problem I have is that my server process returns some content to
    the IFrame to complete form processing and to report any errors that
    might have occured. Here's an example of what may be written back:
    >
    <html>
    <head>
    <script type="text/javascript">
    function completed() {
        window.parent.r eportsCompleted ();}
    >
    </script>
    <body onload="complet ed();">
    <error>The document type .doc is not supported.</error>
    </body>
    </html>
    >
    Now this does properly call the reportsComplete d method of the parent
    frame. The problem I am having is reading the contents of any <error>
    tags if they exist:
    >
    function reportsComplete d() {
        var frame = frames['upload_frame'];
        if (frame.document .getElementsByT agName("error") .length 0) { //
    there were errors...
            var message = "The following error(s) occured:";
            for (var i = 0; i <
    frame.document. getElementsByTa gName("error"). length; i++) {
                message += "\n" +
    frame.document. getElementsByTa gName("error")[i].nodeValue();
            }
            alert(message);
        }
    >
    }
    >
    The problem is that I never get the contents of the error tags
    displayed. I only see an alert window that says "The following
    error(s) occured:".
    >
    What am I doing wrong?
    why not use .innerHTML instead of your non existent .nodeValue()?
    The nodeValue property of the Node interface returns or sets the value of the current node.

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: Problem posting form to an IFrame

      Tom Cole wrote:
      [...]
      The problem I have is that my server process returns some content to
      the IFrame to complete form processing and to report any errors that
      might have occured. Here's an example of what may be written back:
      >
      <html>
      <head>
      <script type="text/javascript">
      function completed() {
      window.parent.r eportsCompleted ();
      }
      </script>
      <body onload="complet ed();">
      <error>The document type .doc is not supported.</error>
      </body>
      </html>
      >
      [...] The problem I am having is reading the contents of any <error>
      tags if they exist:
      >
      function reportsComplete d() {
      var frame = frames['upload_frame'];
      if (frame.document .getElementsByT agName("error") .length 0) { //
      there were errors...
      Use instead:

      if (frame)
      {
      // add feature test here
      var c = frame.document. getElementsByTa gName("error");

      var len = c.length;

      if (len 0)
      {
      var message = "The following error(s) occured:";
      for (var i = 0; i <
      .length; i++) {
      var message = [];

      for (var i = 0; i < len; i++)
      {
      message += "\n" +
      frame.document. getElementsByTa gName("error")[i].nodeValue();
      message.push(c[i].nodeValue;
      }
      alert(message);
      }

      window.alert(me ssage.join("\n" ));
      }
      }
      }
      The problem is that I never get the contents of the error tags
      displayed. I only see an alert window that says "The following
      error(s) occured:".
      >
      What am I doing wrong?
      Using non-HTML elements in a supposed-to-be HTML document,
      and calling a property although it is not a method.


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



      PointedEars
      --
      Anyone who slaps a 'this page is best viewed with Browser X' label on
      a Web page appears to be yearning for the bad old days, before the Web,
      when you had very little chance of reading a document written on another
      computer, another word processor, or another network. -- Tim Berners-Lee

      Comment

      • gunnrosebutpeace

        #4
        Re: Problem posting form to an IFrame

        the <erroris not standard HTML elements then different browsers have
        diffent behavior on unknow tag

        for IE, you should define a namespace for custom elements
        (xmlns:my="http ://xxxx....", then use my:error, then use
        document.getELe mentsByTagName( "error"))
        for Firefox, you need not to define namespace, but you have to write
        document.getEle mentsByTagName( "my:error") ;
        It'd better to use standard HTML element (p, span) and innerHTML.

        On Apr 17, 2:30 am, Tom Cole <tco...@gmail.c omwrote:
        I have a rather complicated business application that uses Ajax. Part
        of this form requires uploading documents, which I cannot do using
        Ajax, so I post the form to an IFrame. This part works just fine.
        >
        The problem I have is that my server process returns some content to
        the IFrame to complete form processing and to report any errors that
        might have occured. Here's an example of what may be written back:
        >
        <html>
        <head>
        <script type="text/javascript">
        function completed() {
            window.parent.r eportsCompleted ();}
        >
        </script>
        <body onload="complet ed();">
        <error>The document type .doc is not supported.</error>
        </body>
        </html>
        >
        Now this does properly call the reportsComplete d method of the parent
        frame. The problem I am having is reading the contents of any <error>
        tags if they exist:
        >
        function reportsComplete d() {
            var frame = frames['upload_frame'];
            if (frame.document .getElementsByT agName("error") .length 0) { //
        there were errors...
                var message = "The following error(s) occured:";
                for (var i = 0; i <
        frame.document. getElementsByTa gName("error"). length; i++) {
                    message += "\n" +
        frame.document. getElementsByTa gName("error")[i].nodeValue();
                }
                alert(message);
            }
        >
        }
        >
        The problem is that I never get the contents of the error tags
        displayed. I only see an alert window that says "The following
        error(s) occured:".
        >
        What am I doing wrong?

        Comment

        • Henry

          #5
          Re: Problem posting form to an IFrame

          On Apr 17, 8:20 am, gunnrosebutpeac e wrote:
          the <erroris not standard HTML elements then different
          browsers have diffent behavior on unknow tag
          >
          for IE, you should define a namespace for custom elements
          (xmlns:my="http ://xxxx....", then use my:error, then use
          document.getELe mentsByTagName( "error"))
          for Firefox, you need not to define namespace, but you have
          to write document.getEle mentsByTagName( "my:error") ;
          It'd better to use standard HTML element (p, span) and
          innerHTML.
          Because different browsers have (and should be expected to have)
          different behaviour when they encounter an unrecognised element in an
          HTML document the specifics of the behaviour of just two of those
          browsers is of very little use or relevance.

          Because the response that includes the message is being generated it
          would be possible to generate it in any form, and the simplest form
          would be to take the character sequence that would otherwise appear in
          the "error" element and appropriately escape it for inclusion in a
          javascript string literal context and insert it as a string literal
          argument to the - reportsComplete d - function call:-

          // with double quotes and line terminators in the string (at minimum)
          // replaces with their equivalent escape sequences.
          window.parent.r eportsCompleted (
          "The document type .doc is not supported"
          );

          (with either no argument or an empty string as an argument in the
          event that there was no error to report.)

          Or assign it to a local variable (perhaps called 'error' for example,
          but preferably something longer and less likely to coincide with a pre-
          existing window property):-

          // with double quotes and line terminators in the string (at minimum)
          // replaces with their equivalent escape sequences.
          var error = "The document type .doc is not supported."

          - and have the reportsComplete d - function access it as:-

          frames['upload_frame'].error

          And in the (apparently likely( event that it is anticipated that there
          be more than one error to report the string literals of the errors
          could instead appear in an array literal.

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: Problem posting form to an IFrame

            Thomas 'PointedEars' Lahn wrote:
            Tom Cole wrote:
            [...]
            > message += "\n" +
            >frame.document .getElementsByT agName("error")[i].nodeValue();
            >
            message.push(c[i].nodeValue;
            message.push(c[i].nodeValue);

            and it should work with Valid markup. Sorry.


            PointedEars
            --
            Prototype.js was written by people who don't know javascript for people
            who don't know javascript. People who don't know javascript are not
            the best source of advice on designing systems that use javascript.
            -- Richard Cornford, cljs, <f806at$ail$1$8 300dec7@news.de mon.co.uk>

            Comment

            • Tom Cole

              #7
              Re: Problem posting form to an IFrame

              On Apr 17, 6:29 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
              wrote:
              Thomas 'PointedEars' Lahn wrote:
              Tom Cole wrote:
              [...]
                          message += "\n" +
              frame.document. getElementsByTa gName("error")[i].nodeValue();
              >
                      message.push(c[i].nodeValue;
              >
                      message.push(c[i].nodeValue);
              >
              and it should work with Valid markup.  Sorry.
              >
              PointedEars
              --
              Prototype.js was written by people who don't know javascript for people
              who don't know javascript. People who don't know javascript are not
              the best source of advice on designing systems that use javascript.
                -- Richard Cornford, cljs, <f806at$ail$1$8 300d...@news.de mon.co.uk>
              Thank you for you assistance. I should have figured using an unknown
              tag would cause unpredictable results. I've changed all the tags to
              <spanelements and use the className to denote them as errors or not.
              This seems to work just fine.

              Comment

              • Captain Paralytic

                #8
                Re: Problem posting form to an IFrame

                On 16 Apr, 20:30, Tom Cole <tco...@gmail.c omwrote:
                I have a rather complicated business application that uses Ajax. Part
                of this form requires uploading documents, which I cannot do using
                Ajax,
                Why not?

                Comment

                • Tom Cole

                  #9
                  Re: Problem posting form to an IFrame

                  On Apr 17, 10:56 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
                  On 16 Apr, 20:30, Tom Cole <tco...@gmail.c omwrote:I have a rather complicated business application that uses Ajax. Part
                  of this form requires uploading documents, which I cannot do using
                  Ajax,
                  >
                  Why not?
                  How would you perform a fileupload with Ajax?

                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: Problem posting form to an IFrame

                    Tom Cole wrote:
                    On Apr 17, 10:56 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
                    >On 16 Apr, 20:30, Tom Cole <tco...@gmail.c omwrote:I have a rather complicated business application that uses Ajax. Part
                    >>of this form requires uploading documents, which I cannot do using
                    >>Ajax,
                    >Why not?
                    >
                    How would you perform a fileupload with Ajax?
                    Submit the form to a dynamically generated (hidden) iframe (the dynamical
                    part is optional), and read back the upload status through an XHR request.
                    BTDT.


                    PointedEars
                    --
                    Anyone who slaps a 'this page is best viewed with Browser X' label on
                    a Web page appears to be yearning for the bad old days, before the Web,
                    when you had very little chance of reading a document written on another
                    computer, another word processor, or another network. -- Tim Berners-Lee

                    Comment

                    • Tom Cole

                      #11
                      Re: Problem posting form to an IFrame

                      On Apr 18, 1:30 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                      wrote:
                      Tom Cole wrote:
                      On Apr 17, 10:56 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
                      On 16 Apr, 20:30, Tom Cole <tco...@gmail.c omwrote:I have a rather complicated business application that uses Ajax. Part
                      >of this form requires uploading documents, which I cannot do using
                      >Ajax,
                      Why not?
                      >
                      How would you perform a fileupload with Ajax?
                      >
                      Submit the form to a dynamically generated (hidden) iframe (the dynamical
                      part is optional), and read back the upload status through an XHR request.
                      BTDT.
                      >
                      PointedEars
                      --
                      Anyone who slaps a 'this page is best viewed with Browser X' label on
                      a Web page appears to be yearning for the bad old days, before the Web,
                      when you had very little chance of reading a document written on another
                      computer, another word processor, or another network. -- Tim Berners-Lee
                      That's what I am doing, I guess I was incorrect in my previous
                      statement. I tend to use the terms "Ajax" and "XHR" as synonyms which
                      I guess they are not.
                      I guess I meant that I could not process document uploads using XHR.

                      Comment

                      • Captain Paralytic

                        #12
                        Re: Problem posting form to an IFrame

                        On 18 Apr, 16:29, Tom Cole <tco...@gmail.c omwrote:
                        On Apr 17, 10:56 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
                        >
                        On 16 Apr, 20:30, Tom Cole <tco...@gmail.c omwrote:I have a rather complicated business application that uses Ajax. Part
                        of this form requires uploading documents, which I cannot do using
                        Ajax,
                        >
                        Why not?
                        >
                        How would you perform a fileupload with Ajax?
                        Take a look at Google Mail. When you select a file for attaching to an
                        email, it gets uploaded immediately in the background, whilst you are
                        still composing the email.

                        Comment

                        • Tom Cole

                          #13
                          Re: Problem posting form to an IFrame

                          On Apr 21, 6:58 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
                          On 18 Apr, 16:29, Tom Cole <tco...@gmail.c omwrote:
                          >
                          On Apr 17, 10:56 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
                          >
                          On 16 Apr, 20:30, Tom Cole <tco...@gmail.c omwrote:I have a rather complicated business application that uses Ajax. Part
                          of this form requires uploading documents, which I cannot do using
                          Ajax,
                          >
                          Why not?
                          >
                          How would you perform a fileupload with Ajax?
                          >
                          Take a look at Google Mail. When you select a file for attaching to an
                          email, it gets uploaded immediately in the background, whilst you are
                          still composing the email.
                          I've noticed that when I use this form submission to an IFrame
                          technique, in Internet Explorer there is a little progress bar that
                          appears in the bottom status bar of rhe browser as if something is
                          still processing, even after my server send the response and my IFrame
                          is populated. It doesn't appear to affect anything, but is strange.
                          Opera, FF, Safari does not exhibit this behaviour.

                          Comment

                          • Captain Paralytic

                            #14
                            Re: Problem posting form to an IFrame

                            On 21 Apr, 14:00, Tom Cole <tco...@gmail.c omwrote:
                            On Apr 21, 6:58 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
                            >
                            On 18 Apr, 16:29, Tom Cole <tco...@gmail.c omwrote:
                            >
                            On Apr 17, 10:56 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
                            >
                            On 16 Apr, 20:30, Tom Cole <tco...@gmail.c omwrote:I have a rather complicated business application that uses Ajax. Part
                            of this form requires uploading documents, which I cannot do using
                            Ajax,
                            >
                            Why not?
                            >
                            How would you perform a fileupload with Ajax?
                            >
                            Take a look at Google Mail. When you select a file for attaching to an
                            email, it gets uploaded immediately in the background, whilst you are
                            still composing the email.
                            >
                            I've noticed that when I use this form submission to an IFrame
                            technique, in Internet Explorer there is a little progress bar that
                            appears in the bottom status bar of rhe browser as if something is
                            still processing, even after my server send the response and my IFrame
                            is populated. It doesn't appear to affect anything, but is strange.
                            Opera, FF, Safari does not exhibit this behaviour.
                            Have you checked GM in IE to see if it does this too?

                            Comment

                            • Tom Cole

                              #15
                              Re: Problem posting form to an IFrame

                              On Apr 21, 10:13 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
                              On 21 Apr, 14:00, Tom Cole <tco...@gmail.c omwrote:
                              >
                              >
                              >
                              >
                              >
                              On Apr 21, 6:58 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
                              >
                              On 18 Apr, 16:29, Tom Cole <tco...@gmail.c omwrote:
                              >
                              On Apr 17, 10:56 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
                              >
                              On 16 Apr, 20:30, Tom Cole <tco...@gmail.c omwrote:I have a rather complicated business application that uses Ajax. Part
                              of this form requires uploading documents, which I cannot do using
                              Ajax,
                              >
                              Why not?
                              >
                              How would you perform a fileupload with Ajax?
                              >
                              Take a look at Google Mail. When you select a file for attaching to an
                              email, it gets uploaded immediately in the background, whilst you are
                              still composing the email.
                              >
                              I've noticed that when I use this form submission to an IFrame
                              technique, in Internet Explorer there is a little progress bar that
                              appears in the bottom status bar of rhe browser as if something is
                              still processing, even after my server send the response and my IFrame
                              is populated. It doesn't appear to affect anything, but is strange.
                              Opera, FF, Safari does not exhibit this behaviour.
                              >
                              Have you checked GM in IE to see if it does this too?- Hide quoted text -
                              >
                              - Show quoted text -
                              It appears to behave the same. And BTW it's in Firefox, not IE that is
                              does this. As I mentioned everything is working just fine so I'll just
                              leave it alone for now.

                              Comment

                              Working...