PDA

View Full Version : Loading external html page with page_request.open('GET', url, true) JS is not working



sohelkapasi
03-16-2010, 08:06 AM
1) Script Title: Loading external html page with page_request.open('GET', url, true) and my JQuery is not working

2) Script URL (on DD): http://www.dynamicdrive.com

3) Describe problem:
Disclaimer: I am not a AJAX programmer and I know JQuery just basics

I have some Ajax code to load the external html pages into my bodyDiv, and the loaded pages into that Div has some JQuery to interactivity, on first time page load they are working fine but when i am loading another page, every JQuery functions are stop working.

On HTML

<a onclick="javascript:ajaxpage('home.html', 'bodyDiv');" href="#first" >Home</a>


Javascrip / AJAX code to load the external page into bodyDIV

/* START Loading Tab pages ------------------------------------------------------------------ */
var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){

/* -------------------------------------- */
var page_request=false;
/* running locally on IE5.5, IE6, IE7 */
if(location.protocol=="file:"){
if(!page_request)try{ page_request=new ActiveXObject("MSXML2.XMLHTTP"); }catch(e){page_request=false;}
if(!page_request)try{ page_request=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){page_request=false;}
}
/* IE7, Firefox, Safari, Opera... */
if(!page_request)try{ page_request=new XMLHttpRequest(); }catch(e){page_request=false;}
/* IE6 */
if(typeof ActiveXObject != "undefined"){
if(!page_request)try{ page_request=new ActiveXObject("MSXML2.XMLHTTP"); }catch(e){page_request=false;}
if(!page_request)try{ page_request=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){page_request=false;}
}
/* IceBrowser */
if(!page_request)try{ page_request=createRequest(); }catch(e){page_request=false;}
/* -------------------------------------- */

page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

Please help me soon, i am stuck