I am writing a browser application that would be fully managed by AJAX (the first time in my life), this means:
- it will be one page located in the browser, loading program components if necessary
- browser history will be, well, no.
- the page will not be refreshed at all
I care about what I have to do with XMLHttpRequests, as I am primarily a C ++ programmer, which was taught when you write an expression like
x = new XMLHttpRequest();
you need deleteafter that.
This question is entirely devoted to memory management, does this object allocated with help remain newin memory even after it completes its "cycle" with readyState == 4 or is it somehow freed, freed, whatchacallit? Honestly, I have no idea at what point this could be released, since the creation of the script will be in HEAD and sit there potentially all day. Should I:
- create one or more reusable objects of type XMLHttpRequest, program the application so that it does not need it more than this limit,
- or does it not matter, and can I allocate as many new XMLHttpRequests as I like?
, , , , "" - . , .
EDIT:
( , ) onClick, XMLHttpRequest :
function submitme(){
var p = document.getElementById('p');
if(typeof p!='undefined' && p!=null){
if(p.value!=""){
var xhr=createXmlHttpRequestObject();
if(xhr!=false){
xhr.open("POST", "blablabla.php", true);
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
if(xhr.status==200){
var adiv = document.getElementById('resultdiv');
xmlResponse = xhr.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
if(typeof adiv !='undefined' && adiv != null){
adiv.innerHTML=xmlDocumentElement.childNodes[0].firstChild.nodeValue;
}
}
}
};
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(p.value);
}
}
}
}
XMLHttpRequest , , xhr, . ? , , none, , readystate==4, onreadystatechange, ? , .