473,386 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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?

Feb 8 '06 #1
6 1266

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?

Feb 8 '06 #2
Zif
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
Feb 8 '06 #3

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.

Feb 8 '06 #4

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.

Feb 8 '06 #5
VK

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.

Feb 8 '06 #6

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"?

Feb 8 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steve High | last post by:
I'm working on an app where a page is created dynamically via a CMS, and I need to save the page similar to the way you can save a 'complete web page' via a browser. I need to save the graphics,...
10
by: Rattanak Song | last post by:
Hi, I'm trying to build a database which can capture a still image from a digital camera or web cam and import to the database via an Object or something like that. Any help would be very...
6
by: vandalo | last post by:
Hi all I developed a service which can convert an office document (word, excel, powerpoint into HTML and save it on the file system To do this I use the "save as" functions of the office...
5
by: ewillyb | last post by:
Hi, ASP.NET has some interesting behavior when the user hits the Enter key. If there are multiple ASP:Buttons (rendered as HTML submits) on the form, when the user hits enter, the first button's...
15
by: Jake Barnes | last post by:
I'm trying to learn AJAX so tonight I sat down and came up with a little toy that I can do tests with. You can see it here: http://www.publicdomainsoftware.org/ajaxExperiment.htm I've got...
2
by: ppuniversal | last post by:
Hi All, My question is as follows: I have a text box and two links.Let the two links be - Show and Save . On clicking the Show , a web page is generated by fetching some data from database...
0
by: nimjerry | last post by:
i am using db2 udb V 9 on aix 5.3 and in db2diag.log alwas has this error occurr below is sample message 2008-03-03-09.45.34.366406+420 I306667A443 LEVEL: Warning PID : 835622 ...
1
by: destiny007 | last post by:
can any one help me to write code to capture selected text from a page but problem is that i am not able to decide where to call the functio.in this case the function is called in all cases of mouse...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.