Import html page in another html page using AJAX

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashwani40
    New Member
    • Apr 2010
    • 1

    Import html page in another html page using AJAX

    I am having a site in which dynamically header part is changing as in each and every page there is a script called which checks the referring url and according to that url script invoke a header.html which is used in AJAX and called as .txt file using XMLHttp.open .

    Complete HTML page is imported but if there is any javascript code exists in the header.txt. Javascript code does not get executed.

    Can any body help me out how to use javascript codeusing AJAX function used as follows.

    Code:
    function loadXMLDoc(url)
    {
    	//alert("URL  "+url);
    	head_url = url + "header.txt";
    	button_url = url + "buttons01.txt";
    	foot_url = url + "footer.txt";
    	fill_url = url + "fill.gif";
    	if (window.XMLHttpRequest)
    	  {// code for IE7+, Firefox, Chrome, Opera, Safari
    		  xmlhttp=new XMLHttpRequest();
    	  }
    	else
    	  {// code for IE6, IE5
    		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	  }
    	xmlhttp.open("GET",head_url,false);
    	xmlhttp.send(null);
    	document.getElementById('header').innerHTML = xmlhttp.responseText;
    	//alert("head url "+head_url);
    	xmlhttp.open("GET",foot_url,false);
    	xmlhttp.send(null);
    	document.getElementById('footer').innerHTML = xmlhttp.responseText;
    	document.getElementById('but').style.backgroundImage = "url(" + fill_url + ")";
    }
    Last edited by Dormilich; Apr 8 '10, 05:45 PM. Reason: Please use [code] tags when posting code
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    'ajaxloaded' JavaScript-code needs to be evaled explicitly ... since it is not a normal page-load ... you have to tell the browser that it should interpret the loaded text as JavaScript-directives

    Comment

    Working...