Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > unable to capture all the HTML of my page,or I'm unable to save it to disk

Reply
Thread Tools

unable to capture all the HTML of my page,or I'm unable to save it to disk

 
 
Jake Barnes
Guest
Posts: n/a
 
      02-08-2006
My thanks to everyone who helped answer my last two questions. You've
all been quite a help to me as I try to learn a bit more about
Javascript this weekend. I've one more question, though I'm not sure
this is the right place to ask it. If you go to this page:

http://www.publicdomainsoftware.org/ajaxExperiment.htm

and click in a box to get the controls, and maybe add some text, then
click the "save" link, This function gets triggered:


function savePage() {
hideDiv("communicationBox");
hideDiv("controller");
hideDiv("deleteBox");
var pageContent = document.documentElement.innerHTML;

askForInput("Your page has been saved", "");
hideDiv("inputBox");
hideDiv("submitButton");
referenceToNewDiv = addItem("inputDiv", "div");
referenceToNewDiv.id = "showSaveResults";

var url = 'savePage.php';
var pars = 'pageText=' + pageContent;
var target = 'showSaveResults';
var myAjax = new Ajax.Updater(target, url, {method: 'post',
parameters: pars});
}


I've not yet incorporated some of the good advice I've been given on
this newsgroup. However, on an unrelated topic, I notice now that I'm
not getting all the HTML. Look at this page, it cut off part way:

http://www.publicdomainsoftware.org/...9_48_57_PM.htm

This was working and now it isn't. I haven't changed my PHP code so
that can't be the problem (its only 12 lines anyway). The PHP code ads
the beginning and end HTML tags, but otherwise doesn't do much other
fwrite() the file to disk.

Perhaps I should ask in a different forum, but can anyone imagine why I
would not get all the HTML?

 
Reply With Quote
 
 
 
 
Jake Barnes
Guest
Posts: n/a
 
      02-08-2006

Jake Barnes wrote:
> My thanks to everyone who helped answer my last two questions. You've
> all been quite a help to me as I try to learn a bit more about
> Javascript this weekend. I've one more question, though I'm not sure
> this is the right place to ask it. If you go to this page:
>
> http://www.publicdomainsoftware.org/ajaxExperiment.htm
>
> and click in a box to get the controls, and maybe add some text, then
> click the "save" link, This function gets triggered:
>
>
> function savePage() {
> hideDiv("communicationBox");
> hideDiv("controller");
> hideDiv("deleteBox");
> var pageContent = document.documentElement.innerHTML;
>
> askForInput("Your page has been saved", "");
> hideDiv("inputBox");
> hideDiv("submitButton");
> referenceToNewDiv = addItem("inputDiv", "div");
> referenceToNewDiv.id = "showSaveResults";
>
> var url = 'savePage.php';
> var pars = 'pageText=' + pageContent;
> var target = 'showSaveResults';
> var myAjax = new Ajax.Updater(target, url, {method: 'post',
> parameters: pars});
> }
>
>
> I've not yet incorporated some of the good advice I've been given on
> this newsgroup. However, on an unrelated topic, I notice now that I'm
> not getting all the HTML. Look at this page, it cut off part way:
>
> http://www.publicdomainsoftware.org/...9_48_57_PM.htm
>
> This was working and now it isn't. I haven't changed my PHP code so
> that can't be the problem (its only 12 lines anyway). The PHP code ads
> the beginning and end HTML tags, but otherwise doesn't do much other
> fwrite() the file to disk.
>
> Perhaps I should ask in a different forum, but can anyone imagine why I
> would not get all the HTML?


Okay, I figured out the answer. Prototype handles the contents of
paramaters like this:

toQueryParams: function() {
var pairs = this.match(/^\??(.*)$/)[1].split('&');
return pairs.inject({}, function(params, pairString) {
var pair = pairString.split('=');
params[pair[0]] = pair[1];
return params;
});
},


so that made me think that the script was choking on the ampersands

"&"

Sure enough, when I look at this page, it ends right before the first
ampersand:

http://www.publicdomainsoftware.org/...0_28_06_PM.htm

So how should I escape the ampersands?

 
Reply With Quote
 
 
 
 
Zif
Guest
Posts: n/a
 
      02-08-2006
Jake Barnes wrote:
> Jake Barnes wrote:
>
>>My thanks to everyone who helped answer my last two questions. You've
>>all been quite a help to me as I try to learn a bit more about
>>Javascript this weekend. I've one more question, though I'm not sure
>>this is the right place to ask it. If you go to this page:
>>
>>http://www.publicdomainsoftware.org/ajaxExperiment.htm
>>
>>and click in a box to get the controls, and maybe add some text, then
>>click the "save" link, This function gets triggered:
>>
>>
>> function savePage() {
>> hideDiv("communicationBox");
>> hideDiv("controller");
>> hideDiv("deleteBox");
>> var pageContent = document.documentElement.innerHTML;
>>
>> askForInput("Your page has been saved", "");
>> hideDiv("inputBox");
>> hideDiv("submitButton");
>> referenceToNewDiv = addItem("inputDiv", "div");
>> referenceToNewDiv.id = "showSaveResults";
>>
>> var url = 'savePage.php';
>> var pars = 'pageText=' + pageContent;
>> var target = 'showSaveResults';
>> var myAjax = new Ajax.Updater(target, url, {method: 'post',
>>parameters: pars});
>> }
>>
>>
>>I've not yet incorporated some of the good advice I've been given on
>>this newsgroup. However, on an unrelated topic, I notice now that I'm
>>not getting all the HTML. Look at this page, it cut off part way:
>>
>>http://www.publicdomainsoftware.org/...9_48_57_PM.htm
>>
>>This was working and now it isn't. I haven't changed my PHP code so
>>that can't be the problem (its only 12 lines anyway). The PHP code ads
>>the beginning and end HTML tags, but otherwise doesn't do much other
>>fwrite() the file to disk.
>>
>>Perhaps I should ask in a different forum, but can anyone imagine why I
>>would not get all the HTML?

>
>
> Okay, I figured out the answer. Prototype handles the contents of
> paramaters like this:
>
> toQueryParams: function() {
> var pairs = this.match(/^\??(.*)$/)[1].split('&');
> return pairs.inject({}, function(params, pairString) {
> var pair = pairString.split('=');
> params[pair[0]] = pair[1];
> return params;
> });
> },
>
>
> so that made me think that the script was choking on the ampersands
>
> "&"
>
> Sure enough, when I look at this page, it ends right before the first
> ampersand:
>
> http://www.publicdomainsoftware.org/...0_28_06_PM.htm
>
> So how should I escape the ampersands?


Presumably what you are showing is the character string as your server
sees it, not the innerHTML property of the page. At a guess, the
ampersand is being interpreted as a query string name/value pair
delimiter so your server is accepting just the first parameter.

Use encodeURIComponent, see the ECMA spec section 15.1.3.2 When you
send it to the document again, use decodeURIComponent.


--
Zif
 
Reply With Quote
 
Jake Barnes
Guest
Posts: n/a
 
      02-08-2006

Zif wrote:
> Jake Barneswrote:>>
>>>>http://www.publicdomainsoftware.org/...9_48_57_PM.htm
> >>
> >>This was working and now it isn't. I haven't changed my PHP code so
> >>that can't be the problem (its only 12 lines anyway). The PHP code ads
> >>the beginning and end HTML tags, but otherwise doesn't do much other
> >>fwrite() the file to disk.
> >>
> >>Perhaps I should ask in a different forum, but can anyone imagine why I
> >>would not get all the HTML?

> >
> >
> > Okay, I figured out the answer. Prototype handles the contents of
> > paramaters like this:
> >
> > toQueryParams: function() {
> > var pairs = this.match(/^\??(.*)$/)[1].split('&');
> > return pairs.inject({}, function(params, pairString) {
> > var pair = pairString.split('=');
> > params[pair[0]] = pair[1];
> > return params;
> > });
> > },
> >
> >
> > so that made me think that the script was choking on the ampersands
> >
> > "&"
> >
> > Sure enough, when I look at this page, it ends right before the first
> > ampersand:
> >
> > http://www.publicdomainsoftware.org/...0_28_06_PM.htm
> >
> > So how should I escape the ampersands?

>
> Presumably what you are showing is the character string as your server
> sees it, not the innerHTML property of the page. At a guess, the
> ampersand is being interpreted as a query string name/value pair
> delimiter so your server is accepting just the first parameter.
>
> Use encodeURIComponent, see the ECMA spec section 15.1.3.2 When you
> send it to the document again, use decodeURIComponent.


Yes, you were right I think, the problem is the ampersand. How do I
change the ampersand to something else? I tried every variation I could
think of on this:

// var newRegX = /&/g;
pageContent.replace(/&/g, "qwertyuioplkjhgfdsazxcvbnm");

// var newRegX = /&/g;
pageContent.replace(/[&]?/g, "qwertyuioplkjhgfdsazxcvbnm");

// var newRegX = /&/g;
pageContent.replace(/\&/g, "qwertyuioplkjhgfdsazxcvbnm");

and a few other variations, none matched? Any suggestions?


I'm leary of using encodeURIComponent since it is my PHP code that must
decode so I won't have access to decodeURIComponent when decoding.

 
Reply With Quote
 
Jake Barnes
Guest
Posts: n/a
 
      02-08-2006

Jake Barnes wrote:
> Zif wrote:
> > Jake Barneswrote:>>
> >>>>http://www.publicdomainsoftware.org/...9_48_57_PM.htm
> > >>
> > >>This was working and now it isn't. I haven't changed my PHP code so
> > >>that can't be the problem (its only 12 lines anyway). The PHP code ads
> > >>the beginning and end HTML tags, but otherwise doesn't do much other
> > >>fwrite() the file to disk.
> > >>
> > >>Perhaps I should ask in a different forum, but can anyone imagine why I
> > >>would not get all the HTML?
> > >
> > >
> > > Okay, I figured out the answer. Prototype handles the contents of
> > > paramaters like this:
> > >
> > > toQueryParams: function() {
> > > var pairs = this.match(/^\??(.*)$/)[1].split('&');
> > > return pairs.inject({}, function(params, pairString) {
> > > var pair = pairString.split('=');
> > > params[pair[0]] = pair[1];
> > > return params;
> > > });
> > > },
> > >
> > >
> > > so that made me think that the script was choking on the ampersands
> > >
> > > "&"
> > >
> > > Sure enough, when I look at this page, it ends right before the first
> > > ampersand:
> > >
> > > http://www.publicdomainsoftware.org/...0_28_06_PM.htm
> > >
> > > So how should I escape the ampersands?

> >
> > Presumably what you are showing is the character string as your server
> > sees it, not the innerHTML property of the page. At a guess, the
> > ampersand is being interpreted as a query string name/value pair
> > delimiter so your server is accepting just the first parameter.
> >
> > Use encodeURIComponent, see the ECMA spec section 15.1.3.2 When you
> > send it to the document again, use decodeURIComponent.

>
> Yes, you were right I think, the problem is the ampersand. How do I
> change the ampersand to something else? I tried every variation I could
> think of on this:
>
> // var newRegX = /&/g;
> pageContent.replace(/&/g, "qwertyuioplkjhgfdsazxcvbnm");
>
> // var newRegX = /&/g;
> pageContent.replace(/[&]?/g, "qwertyuioplkjhgfdsazxcvbnm");
>
> // var newRegX = /&/g;
> pageContent.replace(/\&/g, "qwertyuioplkjhgfdsazxcvbnm");
>
> and a few other variations, none matched? Any suggestions?
>
>
> I'm leary of using encodeURIComponent since it is my PHP code that must
> decode so I won't have access to decodeURIComponent when decoding.


My mistake. How interesting. I did this:

pageText = encodeURIComponent(pageText);

and I sent that to my PHP script. Somewhere along the way it got
converted back to normal. I did not have to decode it at all.

 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      02-08-2006

Jake Barnes wrote:
> How interesting. I did this:
>
> pageText = encodeURIComponent(pageText);
>
> and I sent that to my PHP script. Somewhere along the way it got
> converted back to normal. I did not have to decode it at all.


PHP doesn't use CGI. It uses its own proprietary communication layer
atop of CGI. Still wondering why the f they did it, but a lot of people
seems to like it
Here is one of benefits. Not related to JavaScript anyway.

 
Reply With Quote
 
news@chthonic.f9.co.uk
Guest
Posts: n/a
 
      02-08-2006

VK wrote:
> Jake Barnes wrote:
> > How interesting. I did this:
> >
> > pageText = encodeURIComponent(pageText);
> >
> > and I sent that to my PHP script. Somewhere along the way it got
> > converted back to normal. I did not have to decode it at all.

>
> PHP doesn't use CGI. It uses its own proprietary communication layer
> atop of CGI. Still wondering why the f they did it, but a lot of people
> seems to like it
> Here is one of benefits. Not related to JavaScript anyway.


What _are_ you talking about?

The original poster had problems because his '&' characters were being
treated as the delimeters between parameters being sent back to his
php page, prematurely truncating the data.

Because he's now encoding them properly (encodeURIcomponent will
change & into %26) this doesn't happen any more.

Did you mean "PHP automatically decodes %xx constructions" when
you said it "doesn't use CGI"?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: {Delayed Write Failed} Windows was unable to save all the data Dshai Windows 64bit 0 12-01-2006 01:13 AM
if you have used createElement() and appendChild() on a page, how do you capture all the HTML to write to PHP? Jake Barnes Javascript 15 02-07-2006 06:31 AM
how to save the out html to a html file on server disk automatically ? sincethe2003 ASP .Net 2 07-14-2004 05:18 PM
Save html-forms data to local disk? grz02 HTML 3 02-18-2004 11:01 PM
Windows was unable to save all the data for the file Support Geek 18 Computer Support 3 07-04-2003 03:23 AM



Advertisments