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

J

Jake Barnes

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/ajaxTest/Tuesday_02_07_2006_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?
 
J

Jake Barnes

Jake said:
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/ajaxTest/Tuesday_02_07_2006_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/ajaxTest/Tuesday_02_07_2006_10_28_06_PM.htm

So how should I escape the ampersands?
 
Z

Zif

Jake said:
Jake said:
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/ajaxTest/Tuesday_02_07_2006_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/ajaxTest/Tuesday_02_07_2006_10_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.
 
J

Jake Barnes

Zif said:
Jake Barneswrote:>>
http://www.publicdomainsoftware.org/ajaxTest/Tuesday_02_07_2006_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/ajaxTest/Tuesday_02_07_2006_10_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.
 
J

Jake Barnes

Jake said:
Zif said:
Jake Barneswrote:>>
http://www.publicdomainsoftware.org/ajaxTest/Tuesday_02_07_2006_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/ajaxTest/Tuesday_02_07_2006_10_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.
 
V

VK

Jake said:
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.
 
N

news

VK said:
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"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top