Passing a lot of data

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

    #1

    Passing a lot of data

    I could use a little help here. I have goodled with not much luck. I
    have been at this for a bit and would appreciate suggestions.

    I have a form (A.php) that collects a lot of data. When I post it, I
    gather the data (in A_process.php) and insert/update into a database
    using php and mysql. I then redirect back to the original page (A.php)
    using a "header" command. This all works fine.

    The customer would like me to put in "print" button that would bring up
    a printable version in another window (B.php). The problem is that I
    want to do this while keeping all the data displayed on the current window.

    I have tried creating a json string so that all I would need is
    json_decode on the php side to convert it into an array and build the
    page. I then did a window.open(). The result was that the string was
    too long for the URI for the server. (It would most likely also get the
    same problem using AJAX since the parameters are in the URI). Using AJAX
    to receive a lot of data from the server is easy. It seems to be very
    hard going in the other direction. So, I am looking for suggestions.

    I am considering doing this entirely in php by changing the print button
    from type "button" to type "submit", testing in the target (processing,
    A_process.php) file that it was the print button that sent it, creating
    a session variable , and then opening a new window (B.php). In that
    window I could read the session variable and destroy it. (I can't just
    target to the new window (B.php), because I need to keep the processing
    page for database submission and returning to an empty generating page
    in the original window (A.php).)

    I guess that this method might work, but there must be a better,
    simpler, and more straightforward solution somewhere.
  • slebetman

    #2
    Re: Passing a lot of data

    On Nov 4, 8:30 am, sheldonlg <sheldonlgwrote :
    <snip>
    ... The result was that the string was
    too long for the URI for the server. (It would most likely also get the
    same problem using AJAX since the parameters are in the URI). Using AJAX
    to receive a lot of data from the server is easy. It seems to be very
    hard going in the other direction. So, I am looking for suggestions.
    >
    This is not really a JS problem per se. But a limitation of URI size.
    You should use POST instead of GET so that the data is transferred in
    the HTTP body instead of the URI.

    Comment

    • David Mark

      #3
      Re: Passing a lot of data

      On Nov 3, 7:30 pm, sheldonlg <sheldonlgwrote :
      I could use a little help here.  I have goodled with not much luck.  I
      have been at this for a bit and would appreciate suggestions.
      >
      I have a form (A.php) that collects a lot of data.  When I post it, I
      gather the data (in A_process.php) and insert/update into a database
      using php and mysql.  I then redirect back to the original page (A.php)
      using a "header" command.  This all works fine.
      Not a command as such, but okay.
      >
      The customer would like me to put in "print" button that would bring up
      Did you point out that there is already a "print" button (or at least
      file menu item) on the browser?
      a printable version in another window (B.php).  The problem is that I
      want to do this while keeping all the data displayed on the current window.
      That is the "print preview" file menu item (in most browsers.)
      >
      I have tried creating a json string so that all I would need is
      [snip]

      Just create a print media style sheet.

      Comment

      • sheldonlg

        #4
        Re: Passing a lot of data

        slebetman wrote:
        On Nov 4, 8:30 am, sheldonlg <sheldonlgwrote :
        ><snip>
        >... The result was that the string was
        >too long for the URI for the server. (It would most likely also get the
        >same problem using AJAX since the parameters are in the URI). Using AJAX
        >to receive a lot of data from the server is easy. It seems to be very
        >hard going in the other direction. So, I am looking for suggestions.
        >>
        This is not really a JS problem per se. But a limitation of URI size.
        You should use POST instead of GET so that the data is transferred in
        the HTTP body instead of the URI.
        Uh, I **DO** have it as POST. The problem is that that I don't want to
        leave the page and so want to do it via Javascript/AJAX. In those, you
        pass the values in the URI to the server php from the javascript. The
        post is for when I process the page to do the database work.

        Comment

        • sheldonlg

          #5
          Re: Passing a lot of data

          David Mark wrote:
          On Nov 3, 7:30 pm, sheldonlg <sheldonlgwrote :
          >I could use a little help here. I have goodled with not much luck. I
          >have been at this for a bit and would appreciate suggestions.
          >>
          >I have a form (A.php) that collects a lot of data. When I post it, I
          >gather the data (in A_process.php) and insert/update into a database
          >using php and mysql. I then redirect back to the original page (A.php)
          >using a "header" command. This all works fine.
          >
          Not a command as such, but okay.
          >
          >The customer would like me to put in "print" button that would bring up
          >
          Did you point out that there is already a "print" button (or at least
          file menu item) on the browser?
          >
          >a printable version in another window (B.php). The problem is that I
          >want to do this while keeping all the data displayed on the current window.
          >
          That is the "print preview" file menu item (in most browsers.)
          >
          >I have tried creating a json string so that all I would need is
          >
          [snip]
          >
          Just create a print media style sheet.
          One problem that I forgot to mention (sorry) is that the page is fixed
          size and so only the unscrolled part that appears on the screen is what
          prints. That is why a "print" button is needed to generated a page not
          so limited. The actual printing is still done with file/print.

          Comment

          • David Mark

            #6
            Re: Passing a lot of data

            On Nov 3, 11:05 pm, sheldonlg <sheldonlgwrote :
            David Mark wrote:
            On Nov 3, 7:30 pm, sheldonlg <sheldonlgwrote :
            I could use a little help here.  I have goodled with not much luck.  I
            have been at this for a bit and would appreciate suggestions.
            >
            I have a form (A.php) that collects a lot of data.  When I post it, I
            gather the data (in A_process.php) and insert/update into a database
            using php and mysql.  I then redirect back to the original page (A.php)
            using a "header" command.  This all works fine.
            >
            Not a command as such, but okay.
            >
            The customer would like me to put in "print" button that would bring up
            >
            Did you point out that there is already a "print" button (or at least
            file menu item) on the browser?
            >
            a printable version in another window (B.php).  The problem is that I
            want to do this while keeping all the data displayed on the current window.
            >
            That is the "print preview" file menu item (in most browsers.)
            >
            I have tried creating a json string so that all I would need is
            >
            [snip]
            >
            Just create a print media style sheet.
            >
            One problem that I forgot to mention (sorry) is that the page is fixed
            size and so only the unscrolled part that appears on the screen is what
            prints.
            In other words, you used CSS to change the flow of the page in some
            way that is not advantageous to printing.
            That is why a "print" button is needed to generated a page not
            so limited.  The actual printing is still done with file/print.
            No, you should override what you did for the screen in a print media
            style sheet (e.g. change an overflow:auto rule to overflow:visibl e.)

            Comment

            • slebetman

              #7
              Re: Passing a lot of data

              On Nov 4, 12:03 pm, sheldonlg <sheldonlgwrote :
              slebetman wrote:
              On Nov 4, 8:30 am, sheldonlg <sheldonlgwrote :
              <snip>
              ... The result was that the string was
              too long for the URI for the server. (It would most likely also get the
              same problem using AJAX since the parameters are in the URI). Using AJAX
              to receive a lot of data from the server is easy. It seems to be very
              hard going in the other direction. So, I am looking for suggestions.
              >
              This is not really a JS problem per se. But a limitation of URI size.
              You should use POST instead of GET so that the data is transferred in
              the HTTP body instead of the URI.
              >
              Uh, I **DO** have it as POST. The problem is that that I don't want to
              leave the page and so want to do it via Javascript/AJAX. In those, you
              pass the values in the URI to the server php from the javascript.
              Not necessarily, AJAX can either do a GET or POST. My advice to you is
              to use a POST:

              var request = new XMLHttpRequest( );
              request.open('P OST', 'http://url/path', true);
              request.send('v ar1=hello&var2= goodbye&var3=bl ah%20blah');

              Comment

              • slebetman

                #8
                Re: Passing a lot of data

                On Nov 4, 1:04 pm, slebetman <slebet...@gmai l.comwrote:
                On Nov 4, 12:03 pm, sheldonlg <sheldonlgwrote :
                >
                >
                >
                slebetman wrote:
                On Nov 4, 8:30 am, sheldonlg <sheldonlgwrote :
                ><snip>
                >... The result was that the string was
                >too long for the URI for the server. (It would most likely also get the
                >same problem using AJAX since the parameters are in the URI). Using AJAX
                >to receive a lot of data from the server is easy. It seems to be very
                >hard going in the other direction. So, I am looking for suggestions.
                >
                This is not really a JS problem per se. But a limitation of URI size.
                You should use POST instead of GET so that the data is transferred in
                the HTTP body instead of the URI.
                >
                Uh, I **DO** have it as POST. The problem is that that I don't want to
                leave the page and so want to do it via Javascript/AJAX. In those, you
                pass the values in the URI to the server php from the javascript.
                >
                Not necessarily, AJAX can either do a GET or POST. My advice to you is
                to use a POST:
                >
                ...
                Sorry, incomplete code what I meant was:

                var request = new XMLHttpRequest( );
                request.open('P OST', 'http://url/path', true);
                request.send('v ar1=hello&var2= goodbye&var3=bl ah%20blah');
                /* ^
                * |
                * see, you can send as large a string as you like
                * in the request body if you use POST.
                */
                request.onready statechange = function() {
                if (request.readyS tate == 4) {
                updatePageWith( request);
                }
                }

                Comment

                • sheldonlg

                  #9
                  Re: Passing a lot of data

                  slebetman wrote:
                  On Nov 4, 12:03 pm, sheldonlg <sheldonlgwrote :
                  >slebetman wrote:
                  >>On Nov 4, 8:30 am, sheldonlg <sheldonlgwrote :
                  >>><snip>
                  >>>... The result was that the string was
                  >>>too long for the URI for the server. (It would most likely also get the
                  >>>same problem using AJAX since the parameters are in the URI). Using AJAX
                  >>>to receive a lot of data from the server is easy. It seems to be very
                  >>>hard going in the other direction. So, I am looking for suggestions.
                  >>This is not really a JS problem per se. But a limitation of URI size.
                  >>You should use POST instead of GET so that the data is transferred in
                  >>the HTTP body instead of the URI.
                  >Uh, I **DO** have it as POST. The problem is that that I don't want to
                  >leave the page and so want to do it via Javascript/AJAX. In those, you
                  >pass the values in the URI to the server php from the javascript.
                  >
                  Not necessarily, AJAX can either do a GET or POST. My advice to you is
                  to use a POST:
                  >
                  var request = new XMLHttpRequest( );
                  request.open('P OST', 'http://url/path', true);
                  request.send('v ar1=hello&var2= goodbye&var3=bl ah%20blah');
                  The request-URI is too large

                  Comment

                  • sheldonlg

                    #10
                    Re: Passing a lot of data

                    slebetman wrote:
                    On Nov 4, 1:04 pm, slebetman <slebet...@gmai l.comwrote:
                    >On Nov 4, 12:03 pm, sheldonlg <sheldonlgwrote :
                    >>
                    >>
                    >>
                    >>slebetman wrote:
                    >>>On Nov 4, 8:30 am, sheldonlg <sheldonlgwrote :
                    >>>><snip>
                    >>>>... The result was that the string was
                    >>>>too long for the URI for the server. (It would most likely also get the
                    >>>>same problem using AJAX since the parameters are in the URI). Using AJAX
                    >>>>to receive a lot of data from the server is easy. It seems to be very
                    >>>>hard going in the other direction. So, I am looking for suggestions.
                    >>>This is not really a JS problem per se. But a limitation of URI size.
                    >>>You should use POST instead of GET so that the data is transferred in
                    >>>the HTTP body instead of the URI.
                    >>Uh, I **DO** have it as POST. The problem is that that I don't want to
                    >>leave the page and so want to do it via Javascript/AJAX. In those, you
                    >>pass the values in the URI to the server php from the javascript.
                    >Not necessarily, AJAX can either do a GET or POST. My advice to you is
                    >to use a POST:
                    >>
                    >...
                    >
                    Sorry, incomplete code what I meant was:
                    >
                    var request = new XMLHttpRequest( );
                    request.open('P OST', 'http://url/path', true);
                    request.send('v ar1=hello&var2= goodbye&var3=bl ah%20blah');
                    /* ^
                    * |
                    * see, you can send as large a string as you like
                    * in the request body if you use POST.
                    */
                    request.onready statechange = function() {
                    if (request.readyS tate == 4) {
                    updatePageWith( request);
                    }
                    }
                    Same thing.

                    Request-URI Too Large
                    The requested URL's length exceeds the capacity limit for this server.

                    Comment

                    • SAM

                      #11
                      Re: Passing a lot of data

                      Le 11/4/08 5:05 AM, sheldonlg a écrit :
                      David Mark wrote:
                      >[snip]
                      >>
                      >Just create a print media style sheet.
                      >
                      One problem that I forgot to mention (sorry) is that the page is fixed
                      size and so only the unscrolled part that appears on the screen is what
                      prints. That is why a "print" button is needed to generated a page not
                      so limited.
                      Did you read what David told ?

                      use a PRINT MEDIA Style Sheet
                      ^^^^^^^^^^^

                      This print stylesheet will fixe the height of the div of datas to 'auto'

                      <style type="text/css">
                      #datas { height: 400px; overflow: auto; }
                      </style>
                      <style type="text/css" media="print">
                      body { background: none; color: black; }
                      #datas { height: auto; overflow: none; }
                      </style>

                      The actual printing is still done with file/print.

                      And ?
                      what's the difference with function print ?

                      When printing via menu or function,
                      the stylesheet for printing will be used and, normaly, all datas will be
                      - shown in preview
                      - printed on paper

                      --
                      sm

                      Comment

                      • SAM

                        #12
                        Re: Passing a lot of data

                        Le 11/4/08 11:58 AM, sheldonlg a écrit :
                        >
                        Request-URI Too Large
                        The requested URL's length exceeds the capacity limit for this server.
                        Have a look here :
                        <http://www.captain.at/howto-ajax-form-post-request.php>
                        and fill the 2 textareas with a lot of datas
                        (I tried with 80.000 characters in each one)

                        Tey set a variable to contain all parameters

                        var params = '', f = document.forms[0].elements;
                        for(var i=0, n=f.length-1; i<n; i++)
                        params += f[i].name+'='+encod eURI(f[i].value)+'&';
                        params += f[f.length-1].name+'='+encod eURI(f[f.length-1].value);




                        request.open('P OST', 'http://url/path', true);
                        request.setRequ estHeader("Cont ent-type",
                        "applicatio n/x-www-form-urlencoded");
                        request.setRequ estHeader("Cont ent-length", params.length);
                        request.setRequ estHeader("Conn ection", "close");
                        request.send( params );

                        --
                        sm

                        Comment

                        • sheldonlg

                          #13
                          Re: Passing a lot of data

                          SAM wrote:
                          Le 11/4/08 11:58 AM, sheldonlg a écrit :
                          >>
                          >Request-URI Too Large
                          >The requested URL's length exceeds the capacity limit for this server.
                          >
                          Have a look here :
                          <http://www.captain.at/howto-ajax-form-post-request.php>
                          and fill the 2 textareas with a lot of datas
                          (I tried with 80.000 characters in each one)
                          >
                          Tey set a variable to contain all parameters
                          >
                          var params = '', f = document.forms[0].elements;
                          for(var i=0, n=f.length-1; i<n; i++)
                          params += f[i].name+'='+encod eURI(f[i].value)+'&';
                          params += f[f.length-1].name+'='+encod eURI(f[f.length-1].value);
                          >
                          >
                          >
                          >
                          request.open('P OST', 'http://url/path', true);
                          request.setRequ estHeader("Cont ent-type",
                          "applicatio n/x-www-form-urlencoded");
                          request.setRequ estHeader("Cont ent-length", params.length);
                          request.setRequ estHeader("Conn ection", "close");
                          request.send( params );
                          >
                          I cut and pasted this exact code into place and it still gave the same
                          message. It was also significantly less than 80,000 characters. It was
                          only 6106 characters. The alert I put in to show what params was also
                          looked quite good.

                          Here is what I pasted in:
                          var params = '', f = document.forms[0].elements;
                          for(var i=0, n=f.length-1; i<n; i++)
                          params += f[i].name+'='+encod eURI(f[i].value)+'&';
                          params += f[f.length-1].name+'='+encod eURI(f[f.length-1].value);
                          alert (params.length) ;
                          alert ( params);
                          var request = new XMLHttpRequest( );
                          request.setRequ estHeader("Cont ent-type",
                          "applicatio n/x-www-form-urlencoded");
                          request.setRequ estHeader("Cont ent-length", params.length);
                          request.setRequ estHeader("Conn ection", "close");
                          request.send(pa rams);
                          }

                          Comment

                          • SAM

                            #14
                            Re: Passing a lot of data

                            Le 11/4/08 6:43 PM, sheldonlg a écrit :
                            SAM wrote:
                            >Le 11/4/08 11:58 AM, sheldonlg a écrit :
                            >>>
                            >>Request-URI Too Large
                            >>The requested URL's length exceeds the capacity limit for this server.
                            >>
                            >Have a look here :
                            ><http://www.captain.at/howto-ajax-form-post-request.php>
                            >>
                            >Tey set a variable to contain all parameters
                            (...)
                            I cut and pasted this exact code into place
                            this "exact" code above could be not good (no tested)
                            Try to use and adapt to your case this of the given link
                            and it still gave the same message.
                            It was also significantly less than 80,000 characters. It was
                            only 6106 characters. The alert I put in to show what params was also
                            looked quite good.
                            then ... I don't know what coud be wrong
                            Here is what I pasted in:
                            var params = '', f = document.forms[0].elements;
                            This loop is only an example,
                            it is only available for text-fields an text-windows
                            (input type=text and textarea)
                            for(var i=0, n=f.length-1; i<n; i++)
                            params += f[i].name+'='+encod eURI(f[i].value)+'&';
                            params += f[f.length-1].name+'='+encod eURI(f[f.length-1].value);
                            alert (params.length) ;
                            alert ( params);
                            var request = new XMLHttpRequest( );
                            some little things are missing here (suppose you didn't paste them ?)
                            request.setRequ estHeader("Cont ent-type",
                            "applicatio n/x-www-form-urlencoded");
                            request.setRequ estHeader("Cont ent-length", params.length);
                            request.setRequ estHeader("Conn ection", "close");
                            request.send(pa rams);
                            }

                            --
                            sm

                            Comment

                            Working...