By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 1,985 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

Passing a lot of data

P: n/a
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.
Nov 4 '08 #1
Share this Question
Share on Google+
13 Replies


P: n/a
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.
Nov 4 '08 #2

P: n/a
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.
Nov 4 '08 #3

P: n/a
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.
Nov 4 '08 #4

P: n/a
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.
Nov 4 '08 #5

P: n/a
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:visible.)
Nov 4 '08 #6

P: n/a
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('POST', 'http://url/path', true);
request.send('var1=hello&var2=goodbye&var3=blah%20 blah');

Nov 4 '08 #7

P: n/a
On Nov 4, 1:04 pm, slebetman <slebet...@gmail.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('POST', 'http://url/path', true);
request.send('var1=hello&var2=goodbye&var3=blah%20 blah');
/* ^
* |
* see, you can send as large a string as you like
* in the request body if you use POST.
*/
request.onreadystatechange = function() {
if (request.readyState == 4) {
updatePageWith(request);
}
}
Nov 4 '08 #8

P: n/a
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('POST', 'http://url/path', true);
request.send('var1=hello&var2=goodbye&var3=blah%20 blah');
The request-URI is too large

Nov 4 '08 #9

P: n/a
slebetman wrote:
On Nov 4, 1:04 pm, slebetman <slebet...@gmail.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('POST', 'http://url/path', true);
request.send('var1=hello&var2=goodbye&var3=blah%20 blah');
/* ^
* |
* see, you can send as large a string as you like
* in the request body if you use POST.
*/
request.onreadystatechange = function() {
if (request.readyState == 4) {
updatePageWith(request);
}
}
Same thing.

Request-URI Too Large
The requested URL's length exceeds the capacity limit for this server.
Nov 4 '08 #10

P: n/a
SAM
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
Nov 4 '08 #11

P: n/a
SAM
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+'='+encodeURI(f[i].value)+'&';
params += f[f.length-1].name+'='+encodeURI(f[f.length-1].value);


request.open('POST', 'http://url/path', true);
request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", params.length);
request.setRequestHeader("Connection", "close");
request.send( params );

--
sm
Nov 4 '08 #12

P: n/a
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+'='+encodeURI(f[i].value)+'&';
params += f[f.length-1].name+'='+encodeURI(f[f.length-1].value);


request.open('POST', 'http://url/path', true);
request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", params.length);
request.setRequestHeader("Connection", "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+'='+encodeURI(f[i].value)+'&';
params += f[f.length-1].name+'='+encodeURI(f[f.length-1].value);
alert (params.length);
alert ( params);
var request = new XMLHttpRequest();
request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", params.length);
request.setRequestHeader("Connection", "close");
request.send(params);
}
Nov 4 '08 #13

P: n/a
SAM
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+'='+encodeURI(f[i].value)+'&';
params += f[f.length-1].name+'='+encodeURI(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.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", params.length);
request.setRequestHeader("Connection", "close");
request.send(params);
}

--
sm
Nov 4 '08 #14

This discussion thread is closed

Replies have been disabled for this discussion.