This is part II of this <a
href="http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/cd54951e0ea277de/639c67f2f7cadb1f?tvc=2&q=Simple+HTML+read%2Fwrite+ question#639c67f2f7cadb1f">
post</a>. I am creating a java script that bascially reads a webpage -
forwards it to an external program/parser/servlet - then [locally]
overwrites the webpage with a slightly modify version.
Basically I have two questions:
(1) Do I need to set my XMLHTTPRequest variable to null after I am
finished using it? I would like to be as secure as possible. I have
seen this in some examples but have not been able to implement it.
If I do NOT need to set it to null then I am finished and you do not
need to read any more.
But if I do have to set it to null, please show me what I am doing
wrong. I think the best place to do that would be in the callback
function, but when i try this I get an error. Here is my code:
///////////////////////////////////////////////////////////
// Method will send the HTML source to a "parser"
// and post the reply
//////////////////////////////////////////////////////////
function post_plain(dom)
{
connection=false;
// We can cope with old IE versions.
// and security blocked creation of the objects.
try {
connection = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e){
try {
connection = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
connection = false;
}
}
if (!connection && typeof XMLHttpRequest!='undefined')
{
connection = new XMLHttpRequest();
}
if(connection) {
// set URL to connect to
var url_ps = "a_secret_address_to_a_secure_servlet";
// method for initializing a post
connection.open("POST", url_ps,true);
// send request header
connection.setRequestHeader("Content-Type", "text/xml");
// method for sending the request
connection.send(dom.body.innerHTML);
connection.onreadystatechange = function() {
if (connection.readyState == 4) {
dom.body.innerHTML = connection.responseText;
// ****** THIS DOES NOT WORK **********
// clean up
// var connection = null;
}
}
}
else{
alert("ERROR - CONNECT == FALSE");
}
}
Thanks for viewing my code. Please feel free to make any sort of
comments or corrections. If you need me to post any more information
just let me know.