The existing AJAX script, which you are talking about is designed in such a manner that the AJAX call will be made before completely loading the page in which you've integrated this script.
If you are looking for a fully DOM based method for handling the response from the server. Then I think it would be better if you use either XML or JSON as the response type from the server to the client. After getting the response use JS DOM routine to construct the document part in your page. Also you have to change some changes in the original AJAX script you are using:
Code:
var page_request = false;
function ajaxinclude(url) {
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject) { // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} catch(e) {
try {
page_request = new ActiveXObject("Microsoft.XMLHTTP")
} catch(e) {}
}
} else
return false
page_request.open('GET', url, false) //get page synchronously
page_request.send(null)
//writecontent(page_request)
}
function writecontent(page_request) {
/*if (window.location.href.indexOf("http") == -1 || page_request.status == 200)
document.write(page_request.responseText);*/
}
I've highlighted the changes I've made.
Then in your window's load event you can call the JS routine that construct the DOM Tree based on the server response
Code:
window.onload = function(){
your_DOM_Constructor_Method(); //You don't have to pass the XHR object as it is a global one and will be accessible inside your method.
}
Here is some good articles about the technique using which you can construct the fully DOM based structure, this articles explains the technique in a step by step manner and can be followed very easily. You can find other good articles about this one.
http://www.quirksmode.org/blog/archi...ax_respon.html
http://www.quirksmode.org/blog/archi..._respon_1.html
Hope this helps.
Bookmarks